News for hackers. Stuff that matters.
Re:Simple, Fast, Practical Non-Blocking and Blocking Concurr... by coder23 on Monday May 26, 2014 @03:10PM (#7801072)
I see a problem with implementing the non-blocking version in C. Compare-and-swap must operate on an entire struct. But for example gcc only allows integer types. Quote from gcc docs:The definition given in the Intel documentation allows only for the use of the types int, long, long long as well as their unsigned counterparts. GCC will allow any integral scalar or pointer type that is 1, 2, 4 or 8 bytes in length.

C11 has a new header stdatomic.h which only allows atomic for integer types.

How do you perform CAS on a struct in C( without using a mutex of course )?

Re:Simple, Fast, Practical Non-Blocking and Blocking Concurr... by gosu on Monday May 26, 2014 @03:34PM (#7801182)
By storing the struct in union with an integral type - or, if you need a value but not an address, casting to such a union. You might also think to just abuse pointer casting, but IIRC that breaks C strict aliasing assumptions and causes GCC's optimizations to do bad things to your program.