[fpc-devel] Threads and alot of crap

Jonas Maebe jonas.maebe at elis.ugent.be
Tue Oct 17 11:03:23 CEST 2006


On 17 okt 2006, at 10:44, Daniƫl Mantione wrote:

> procedure intRTLEventSetEvent(AEvent: PRTLEvent);
> var p:pintrtlevent;
>
> begin
>   p:=pintrtlevent(aevent);
>   pthread_mutex_lock(@p^.mutex);
>   pthread_cond_signal(@p^.condvar);
>   pthread_mutex_unlock(@p^.mutex);
> end;
>
> procedure intRTLEventStartWait(AEvent: PRTLEvent);
> var p:pintrtlevent;
>
> begin
>   p:=pintrtlevent(aevent);
>   pthread_mutex_lock(@p^.mutex);
> end;
>
> procedure intRTLEventWaitFor(AEvent: PRTLEvent);
> var p:pintrtlevent;
>
> begin
>   p:=pintrtlevent(aevent);
>   pthread_cond_wait(@p^.condvar, @p^.mutex);
>   pthread_mutex_unlock(@p^.mutex);
> end;

This last pthread_mutex_unlock does not make sense to me. From the  
pthread_cond_wait man page:

      The pthread_cond_wait() function atomically unlocks the mutex  
argument
      and waits on the cond argument.

So the mutex should already be unlocked afterwards. Further, what is  
the lock/unlock for in the intRTLEventSetEvent? pthread_cond_signal  
can perfectly deal with multiple threads simultaneously signalling  
the same condition variable (pthreads is a multithreading api, not a  
random non-reentrant piece of code).


Jonas


More information about the fpc-devel mailing list