[M3devel] Latest ThreadPThread

Tony Hosking hosking at cs.purdue.edu
Wed Apr 22 04:14:13 CEST 2009


On 22 Apr 2009, at 04:29, Carson Gaspar wrote:

> Tony Hosking wrote:
>
>> I'm pretty sure that is only in the user-level threading model,  
>> where thread switches only occur on delivery of a signal to the  
>> process. I am unaware of any OS/hardware that will deliver a thread  
>> switch signal in the middle of INC/DEC.  So, effectively, for user  
>> level threads INC/DEC can be assumed atomic.  That's what the  
>> comments are meant to imply.   Outside ThreadPosix, all other uses  
>> of INC/DEC manipulate state that is already protected appropriately  
>> by a lock so should be thread safe.
>
> I'm not sure what you mean by INC/DEC... but if it involves changing  
> a value in memory (as opposed to a register), then it is _not_  
> atomic and _must_ use a lock. The most common mistake I've seen is a  
> variable modified in a signal handler and in the main code,  
> especially SIGCHLD. "nchildren++" is _not_ signal or thread safe.

Indeed, on a multi-processor with system-scheduled threads that is the  
case.  My comments pertain only to the rather narrow implementation of  
single-processor user-level threads using signal-handling that the  
Modula-3 user-level threads implementation uses/used.  That  
implementation is pretty much unused on modern platforms where we  
support proper hardware-level parallelism.  There, all memory  
operations must be protected by proper synchronization.




More information about the M3devel mailing list