Note that there are some explanatory texts on larger screens.

plurals
  1. POx86 equivalent for LWARX and STWCX
    text
    copied!<p>I'm looking for an equivalent of LWARX and STWCX (as found on the PowerPC processors) or a way to implement similar functionality on the x86 platform. Also, where would be the best place to find out about such things (i.e. good articles/web sites/forums for lock/wait-free programing).</p> <hr> <p><strong>Edit</strong><br> I think I might need to give more details as it is being assumed that I'm just looking for a CAS (compare and swap) operation. What I'm trying to do is implement a lock-free reference counting system with smart pointers that can be accessed and changed by multiple threads. I basically need a way to implement the following function on an x86 processor.</p> <pre>int* IncrementAndRetrieve(int **ptr) { int val; int *pval; do { // fetch the pointer to the value pval = *ptr; // if its NULL, then just return NULL, the smart pointer // will then become NULL as well if(pval == NULL) return NULL; // Grab the reference count val = lwarx(pval); // make sure the pointer we grabbed the value from // is still the same one referred to by 'ptr' if(pval != *ptr) continue; // Increment the reference count via 'stwcx' if any other threads // have done anything that could potentially break then it should // fail and try again } while(!stwcx(pval, val + 1)); return pval; } </pre> <p>I really need something that mimics LWARX and STWCX fairly accurately to pull this off (I can't figure out a way to do this with the CompareExchange, swap or add functions I've so far found for the x86).</p> <p>Thanks</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload