[fpc-pascal] Is TFPList thread safe?

Michael Schnell mschnell at lumino.de
Tue Oct 7 09:22:14 CEST 2014


On 10/06/2014 05:55 PM, Dennis Poon wrote:
>
>
> function TThreadList.LockList: TList;
>   begin
>     Result:=FList;
>     System.EnterCriticalSection(FLock);
>   end;
>
Yep.

System.EnterCriticalSection is a procedure variable that is set 
according to the OS and arch the project is compiled for.

In Linux without  UseCThreads it is just an empty function. (OK here 
creating threads is not allowed)
In Linux with  UseCThreads it is just an empty function it is a call to 
pthread_mutex_lock, which is in the pthreadlib so file and calls FUTEX 
or MUTEX, such as appropriate. (So don't try to "optimize" !!! )
In Windows I suppose it does a call to the Windows system DLL that 
supposedly does  a FUTEX workalike.  (So don't try to "optimize" !!! )


>
> There is no special optimization at all.  It simply calls
>   System.EnterCriticalSection(FLock),
> so performance should be JUST THE SAME as wrapping a pair of critical 
> section enter/leave around the code ourselves.
Yep. (So don't try to "optimize" !!! )

-Michael



More information about the fpc-pascal mailing list