Quantcast
Channel: GameDev.net
Viewing all articles
Browse latest Browse all 17560

Please explain multithreading example

$
0
0

Hello,

i am currently trying to understand the following code example from the book "C++ Concurrency in Action":

// Simplified sample in pseudo-C++ (see page 133 for original)
atomic x,y,z;
void write_x() { x.store(true, release); }
void write_y() { y.store(true, release); }
void read_x_then_y() { while (!x.load(acquire)); if (y.load(acquire)) ++z; }
void read_y_then_x() { while (!y.load(acquire)); if (x.load(acquire)) ++z; }
void main() { x=false;y=false;z=0; thread a(write_x); thread b(write_y); thread c(read_x_then_y); thread d(read_y_then_x); join(a,b,c,d); assert(z.load()≠0); }

And that is, I don't …


Viewing all articles
Browse latest Browse all 17560

Trending Articles