anyone here who can explain to me why this code is not working as expected? Is it a bug or not?
Code: Select all
Structure pthread_cond_t
l.l
EndStructure
Structure pthread_mutex_t
l.l
EndStructure
ImportC ""
pthread_cond_signal(*cond)
EndImport
Define cond.pthread_cond_t
; Create condition variable
pthread_cond_init_(@cond, 0)
; Create mutex (internally pthread_mutex_init())
Define *mutex.pthread_mutex_t = CreateMutex()
Debug "locked? " + *mutex\l
; Lock mutex because pthread_cond_wait() needs this.
LockMutex(*mutex)
Debug "locked? " + *mutex\l
Delay(100)
Procedure signal2(*cond.pthread_cond_t)
Delay(1000)
Debug *cond\l
Protected l.l = pthread_cond_signal(*cond)
Debug "signal " + l
EndProcedure
; Create a thread which signals the following waiter.
CreateThread(@signal2(), @cond)
Delay(100)
; Wait until the threads sends a signal.
pthread_cond_wait_(@cond, *mutex)
Delay(2000)
pthread_cond_destroy_(@cond)
FreeMutex(*mutex)