Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / fpc-other / 2011-06

Multi-threaded programming (was: volatile variables)

1 message · 1 person ·

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Jonas Maebe

(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

Reply by email