Skip to content

Commit 167a6ea

Browse files
Merge pull request #1107 from ocsigen/fix-extracted-from-1103
Fix pool_mutex initialization order on Windows
2 parents 2dfafc0 + 3d41302 commit 167a6ea

2 files changed

Lines changed: 13 additions & 2 deletions

File tree

CHANGES

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
===== 6.1.2 =====
2+
3+
====== Fixes ======
4+
5+
* fix initialisation of lock on Windows. (Mark Elvers, David Allsopp, #1103, #1107, #1104)
6+
17
===== 6.1.1 =====
28

39
====== Fixes ======

src/unix/lwt_unix_stubs.c

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1063,6 +1063,13 @@ CAMLprim value lwt_unix_start_job(value val_job, value val_async_method) {
10631063
lwt_unix_async_method async_method = Int_val(val_async_method);
10641064
int done = 0;
10651065

1066+
/* Ensure threading is initialized before using pool_mutex.
1067+
On Windows, CRITICAL_SECTION must be initialized before use;
1068+
unlike pthreads, zero-initialized CRITICAL_SECTIONs are invalid. */
1069+
if (async_method != LWT_UNIX_ASYNC_METHOD_NONE) {
1070+
initialize_threading();
1071+
}
1072+
10661073
/* Fallback to synchronous call if there is no worker available and
10671074
we can not launch more threads. */
10681075
if (async_method != LWT_UNIX_ASYNC_METHOD_NONE) {
@@ -1087,8 +1094,6 @@ CAMLprim value lwt_unix_start_job(value val_job, value val_async_method) {
10871094

10881095
case LWT_UNIX_ASYNC_METHOD_DETACH:
10891096
case LWT_UNIX_ASYNC_METHOD_SWITCH:
1090-
initialize_threading();
1091-
10921097
lwt_unix_mutex_init(&job->mutex);
10931098

10941099
lwt_unix_mutex_lock(&pool_mutex);

0 commit comments

Comments
 (0)