(moved to fpc-other list, because unrelated to FPC development)
Michael Schnell wrote 8 lines
Regarding FPC, TCriticalSection is a decent encapsulation for
pthread_mutex_... when used in this way.
But e.g. if you use a TThreadList instance "myList" with multiple
threads it can't be the way to go to include any occurrence of
myList.xxx by a critical section just to make sure that the cache
synchronization has happened and the instance variable itself in
fact is valid.
That's where optimization comes in, where you try to structure your program in such a way that the number of points where synchronisation is required is minimised. There is no general solution, and if the synchronisation happens at the tthreadlist level then you do need a lock/unlock (or equivalent) to make sure that everything is data-race free and synchronized across all cores.
That is a general part of learning multi-threaded programming.
Jonas
