[ILUG] Test-and-set in C/C++

Vincent Cunniffe vincent at cunniffe.net
Fri Oct 1 10:56:01 IST 2004


Hi,

I've been unable to find any way of doing a proper test-and-set command 
in C/C++... anyone know a way of doing this?

This is going to be executed in a signal, possibly re-entrant, so it 
can't be wrapped in a semaphore, mutex, or anything else : it has to be 
a single, atomic, test-and-set operation which cannot possibly be 
interrupted or pre-empted. This is also executing in a threaded environment.

I've seen various pieces of sample code stupidly claiming to be test and 
set, such as 'if (i==0) {i++; return true;}', but haven't found anything 
which is basically an exposure of the underlying atomic hardware 
instruction.

Vin



More information about the ILUG mailing list