queue - How to implement double compare and swap in C/Linux? -


i reading paper "simple, fast, , practical non-blocking , blocking concurrent queue algorithms" , realized that assume computer implements following pseudo-code atomically:

cas(q->tail,tail,<next.ptr,next.count+1>) 

where q->tail , tail pointer , instance of struct containing pointer , counter.

i know gcc provides couple of build-ins single word compare , swap in c. however, possible implement non-blocking atomic double compare , swap single compare , swap in c (using linux)? right approach implement pseudo-code of referenced paper?

i don't know of cas operations work on 2 distinct memory locations. however, it's possible paper using struct pointer , counter workaround treat both fields larger type, , therefore, change both atomically.

assuming have struct of 2 fields, pointer , counter: pointer size of 4 bytes, counter size of 4 bytes; aligned without padding struct size of 8 bytes. assuming have cas operation handles values of 8 bytes (such pointer 64-bit integer). can prepare struct values separately, , use cas operation on struct whole change 2 values @ once.


Comments

Popular posts from this blog

ruby on rails - Is it the correct way to implement belongs_to relation with factory girl? -

geolocation - Windows Phone 8 - Keeping background location tracking active beyond four hours -

Uncaught TypeError: Cannot read property 'parentNode' of null javascript -