
Am Friday 04 December 2009 18:06:31 schrieb Phil Endecott:
Hi Helge,
In your x86 code you have:
bool compare_exchange_strong(T &e, T d, memory_order order=memory_order_seq_cst) volatile { T prev=e; __asm__ __volatile__("lock cmpxchgb %1, %2\n" : "=a" (prev) : "q" (d), "m" (i), "a" (e) : "memory"); bool success=(prev==e); e=prev; return success; }
Can you explain why 'e' is a reference and why you assign back to it?
the standard requires the "found" value to be passed back, so you don't need to perform another "load" on retrying the operation
Maybe it would help if you could write out what that asm does in pseudo-code. The kernel_cmpxchg that I have does:
there is a pseudo-code explanation in the boost::atomic class documentation Helge