Am 24.07.2012 13:21, schrieb OBones:
Thomas Schatzl wrote:
This code is not thread safe at all. A thread switch after the while
loop and before the increment will not prevent progress on other
threads, so multiple threads can enter the "critical section".
Well, yes, even if under Windows it's rare that a thread is preempted
right in the middle of its execution. At least that's what my own
experience has told me and why I'm calling Sleep in the while loop, so
that the thread yields to other ones.

Windows will preempt a thread once it's time slice has run out or it yields it's execution. In the first case it does not matter whether the thread is inside some function execution, because the sheduler does not know about such a concept.

Regards,
Sven
_______________________________________________
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-pascal

Reply via email to