An introduction to lockless algorithms
An introduction to lockless algorithms
Posted Feb 20, 2021 3:47 UTC (Sat) by kurogane (guest, #83248)Parent article: An introduction to lockless algorithms
I'm afraid I keep on interpreting the message example as being code that will only read datum->x once x was already assigned.
thread 1 thread 2
-------------------------------- ------------------------
a.x = 1;
message = &a; datum = message;
if (datum != NULL)
printk("%d\n", datum->x);
That is that thread 2 will do nothing if "message" and hence "datum" pointer is still null, or receive a pointer to "a" after it already has its x member assigned.
Is the point that thread 2 was supposed to printk(), i.e. wait until datum is non-null? When I first saw this code it seemed natural to me that thread 2 was meant to be a 'just do nothing if object was not ready' thread though.
Or is the point there might be reordering, that CPU instruction-wise the stores and loads might not be not ordered as the C code above is?
