Previous | Next --- Slide 11 of 60
Back to Lecture Thumbnails
sareyan

Stupid question, why isn't get thread safe? It looks like it's read-only. (For that matter, why isn't it thread safe when there is one set-er?)

pinkpanther

@sareyan get is only thread safe if there is a thread calling set. If there is a thread calling get, a memory location corresponding to e.next may be read in get while being written in set, and concurrent memory read/write to the same address results in undefined behavior (at least in C++ ... not sure about Java, though). I think if we knew that the assembly code instructions were reasonable/predictable, then we could safely run multiple gets + a single set at once (the gets may or may not find the new value, which is expected)

Please log in to leave a comment.