You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Consider that 4 threads A, B, C, D. Assume that we have the queue with 3 elements and thread A is putting a new element 4 into the queue, in which case it's running in enqueue. After A executes #2 successfully, the current state of the queue looks like this:
Assume that A is switched out by scheduler. Now thread B, C, D are trying to dequeue elements from the queue. They run to #4 and delete 1, 2, 3 respectively.
Note that current state of prev is freed and no longer valid. However, if A resumes at #3, the prevhead is actually deleted by other threads and it's UB now.
The text was updated successfully, but these errors were encountered:
The following code comes from 7ab32b4
Consider that 4 threads A, B, C, D. Assume that we have the queue with 3 elements and thread A is putting a new element
4
into the queue, in which case it's running inenqueue
. After A executes #2 successfully, the current state of the queue looks like this:|---------------------- head 1 -> 2 -> 3 --> 4 ^ |------------------ prev
Assume that A is switched out by scheduler. Now thread B, C, D are trying to dequeue elements from the queue. They run to #4 and delete 1, 2, 3 respectively.
Note that current state of
prev
is freed and no longer valid. However, if A resumes at #3, theprevhead
is actually deleted by other threads and it's UB now.The text was updated successfully, but these errors were encountered: