[M3devel] Latest ThreadPThread

Carson Gaspar carson at taltos.org
Tue Apr 21 20:29:28 CEST 2009


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.

If you're talking about purely register instructions, please ignore me ;-)

-- 
Carson




More information about the M3devel mailing list