[fpc-devel] Threads and alot of crap
Daniël Mantione
daniel.mantione at freepascal.org
Tue Oct 17 10:44:01 CEST 2006
Op Tue, 17 Oct 2006, schreef Jonas Maebe:
> =
> On 17 okt 2006, at 09:25, Dani=EBl Mantione wrote:
> =
> > If I compare my implementation of the Chameneos benchmark with the one
> > from Marc (which uses Pthreads directly), mine is about two times slowe=
r.
> > This is propably caused that our thread functions often require multiple
> > Pthread calls,
> =
> Where? I only see this in starting/initialising/stopping/destructing thin=
gs.
> The actual locking etc use one pthread call in all cases afaics. Of cours=
e,
> starting a Pascal thread requires initialising all the threadvars etc, but
> that is not going to change if you use something else than pthreads.
For example:
procedure intRTLEventSetEvent(AEvent: PRTLEvent);
var p:pintrtlevent;
begin
p:=3Dpintrtlevent(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:=3Dpintrtlevent(aevent);
pthread_mutex_lock(@p^.mutex);
end;
procedure intRTLEventWaitFor(AEvent: PRTLEvent);
var p:pintrtlevent;
begin
p:=3Dpintrtlevent(aevent);
pthread_cond_wait(@p^.condvar, @p^.mutex);
pthread_mutex_unlock(@p^.mutex);
end;
I'm not 100% sure yet, but I believe you can implement a set-event with a
FUTEX_WAKE, and a waitfor with an unconditional FUTEX_WAIT, which would =
mean a lot less calls.
Dani=EBl
More information about the fpc-devel
mailing list