You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Original bug ID: 4979 Reporter: gerd Assigned to:@xavierleroy Status: closed (set by @xavierleroy on 2011-05-29T10:19:34Z) Resolution: fixed Priority: normal Severity: minor Version: 3.11.1 Fixed in version: 3.12.0+dev Category: ~DO NOT USE (was: OCaml general)
Bug description
Just got an error Sys_error("Mutex.lock: error code 0") in a win32 program using threads heavily. I wondered how that was possible. Apparently, the true reason of the error is hidden, and the error code 0 is a lie. (It's usually an invalid descriptor.)
So I dug a bit deeper into the ocaml runtime, and found this (systhreads/win32.c):
CAMLprim value caml_mutex_lock(value mut)
{
int retcode;
Begin_root(mut) /* prevent deallocation of mutex */
enter_blocking_section();
retcode = WaitForSingleObject(Mutex_val(mut), INFINITE);
leave_blocking_section();
End_roots();
if (retcode == WAIT_FAILED) caml_wthread_error("Mutex.lock");
return Val_unit;
}
In caml_wthread_error, the win32 function GetLastError is used to obtain the error code. However, this code was already overwritten in leave_block_section (there is a WaitForSingleObject right at the beginning to get the master lock).
Suggested fix: Get the error code before leave_blocking_section, and pass it to caml_wthread_error.
The text was updated successfully, but these errors were encountered:
Original bug ID: 4979
Reporter: gerd
Assigned to: @xavierleroy
Status: closed (set by @xavierleroy on 2011-05-29T10:19:34Z)
Resolution: fixed
Priority: normal
Severity: minor
Version: 3.11.1
Fixed in version: 3.12.0+dev
Category: ~DO NOT USE (was: OCaml general)
Bug description
Just got an error Sys_error("Mutex.lock: error code 0") in a win32 program using threads heavily. I wondered how that was possible. Apparently, the true reason of the error is hidden, and the error code 0 is a lie. (It's usually an invalid descriptor.)
So I dug a bit deeper into the ocaml runtime, and found this (systhreads/win32.c):
CAMLprim value caml_mutex_lock(value mut)
{
int retcode;
Begin_root(mut) /* prevent deallocation of mutex */
enter_blocking_section();
retcode = WaitForSingleObject(Mutex_val(mut), INFINITE);
leave_blocking_section();
End_roots();
if (retcode == WAIT_FAILED) caml_wthread_error("Mutex.lock");
return Val_unit;
}
In caml_wthread_error, the win32 function GetLastError is used to obtain the error code. However, this code was already overwritten in leave_block_section (there is a WaitForSingleObject right at the beginning to get the master lock).
Suggested fix: Get the error code before leave_blocking_section, and pass it to caml_wthread_error.
The text was updated successfully, but these errors were encountered: