using asm() to execute an atomic subtraction instruction
jonnyjack
jonnyjack7@gmail.com
Thu Sep 27 13:45:00 GMT 2012
For a school project, I have to implement a simple atomic_sub() function in
c. The implementation must use the asm() function.
Right now, my code looks like this
void atomic_sub( int * value, int dec_val) {
asm ("LOCK SUB (%0), %1;\n"
:
: "r" (value), "r" (dec_val)
: "memory");
}
The intention is for "value" to decrement by "dec_val" atomically, but when
I try to compile I get the following error.
"locking.c:28: Error: expecting lockable instruction after 'lock'"
This asm() call is on line 28, so this is the instruction the error is
referring to. Does anyone know why this isn't a lockable instruction?
According to the documentation from Intel I've read, a sub with a
destination of a memory address is lockable. Any ideas?
--
View this message in context: http://gcc.1065356.n5.nabble.com/using-asm-to-execute-an-atomic-subtraction-instruction-tp873076.html
Sent from the gcc - Help mailing list archive at Nabble.com.
More information about the Gcc-help
mailing list