diff --git a/rtl/unix/cthreads.pp b/rtl/unix/cthreads.pp index dd518e0c37..903b283369 100644 --- a/rtl/unix/cthreads.pp +++ b/rtl/unix/cthreads.pp @@ -627,7 +627,9 @@ begin { the process exits } sem_unlink(name) else - cIntSemaphoreOpen:=NIL; + { 0 is a valid for sem_open on some platforms; pointer(-1) shouldn't + be valid anywhere, even for sem_init } + cIntSemaphoreOpen:=pointer(-1); end; {$endif} @@ -644,7 +646,9 @@ begin if sem_init(PSemaphore(cIntSemaphoreInit), 0, ord(initvalue)) <> 0 then begin FreeMem(cIntSemaphoreInit); - cIntSemaphoreInit:=NIL; + { 0 is a valid for sem_open on some platforms; pointer(-1) shouldn't + be valid anywhere, even for sem_init } + cIntSemaphoreInit:=pointer(-1); end; {$else} {$ifdef has_sem_open} @@ -658,7 +662,9 @@ begin if (fppipe(PFilDes(cIntSemaphoreInit)^) <> 0) then begin FreeMem(cIntSemaphoreInit); - cIntSemaphoreInit:=nil; + { 0 is a valid for sem_open on some platforms; pointer(-1) shouldn't + be valid anywhere, even for sem_init } + cIntSemaphoreInit:=pointer(-1); end else if initvalue then cSemaphorePost(cIntSemaphoreInit); diff --git a/rtl/unix/tthread.inc b/rtl/unix/tthread.inc index 0dd8e82d91..eb5efad6a5 100644 --- a/rtl/unix/tthread.inc +++ b/rtl/unix/tthread.inc @@ -178,7 +178,7 @@ begin // via BeginThread and creates the first TThread Object in there! InitThreads; FSem := CurrentTM.SemaphoreInit(); - if FSem = nil then + if FSem = pointer(-1) then raise EThread.create('Semaphore init failed (possibly too many concurrent threads)'); WRITE_DEBUG('thread ', ptruint(self), ' created semaphore ', ptruint(FSem)); FSuspended := CreateSuspended;