Join GitHub today
GitHub is home to over 31 million developers working together to host and review code, manage projects, and build software together.Sign up
win32: GetLastError and threads #4979
Original bug ID: 4979
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)
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.