Fix. Correctly handle error from `_beginthreadex` (close #12)
authorAlexey Melnichuk <alexeymelnichuck@gmail.com>
Tue, 21 Mar 2017 12:48:31 +0000 (15:48 +0300)
committerAlexey Melnichuk <alexeymelnichuck@gmail.com>
Tue, 21 Mar 2017 12:48:31 +0000 (15:48 +0300)
`_beginthread` returns -1 in case of error, but `_beginthreadex` returns 0.

https://msdn.microsoft.com/en-us/library/kdzttdcb.aspx

src/llthread.c

index eee7290..eb0c861 100644 (file)
@@ -384,6 +384,9 @@ static int llthread_start(llthread_t *this, int start_detached, int joinable) {
 
 #ifndef USE_PTHREAD
   this->thread = (HANDLE)_beginthreadex(NULL, 0, llthread_child_thread_run, child, 0, NULL);
+  if(0 == this->thread){
+    this->thread = INVALID_THREAD;
+  }
   if(INVALID_THREAD == this->thread){
     rc = -1;
   }