Googles appar
Huvudmeny

Post a Comment On: cbloom rants

"11-28-11 - Some lock-free rambling"

7 Comments -

1 – 7 of 7
Blogger won3d said...

http://duckduckgo.com/?q=%23StoreLoad

Google should do a better job with symbols.

November 28, 2011 at 8:08 PM

Blogger ryg said...

Don't see the deadlock in the first "notify_one" example. Yes, both notifies might go to say Thread 3, so Thread 4 is not woken up, but how is that a deadlock?

I guess the general rule is that if you have N waiters on a waitset and call notify_one N times, you'll wake up <=N threada, not exactly N threads. More precisely, it gives you "atomic(notify_one_waiter) then atomic(remove_waiter)", not "atomic(notify_one_waiter_then_remove)", which would be a much nicer (and more intuitive) primitive. Correct?

November 29, 2011 at 2:34 AM

Blogger cbloom said...

"Don't see the deadlock in the first "notify_one" example. Yes, both notifies might go to say Thread 3, so Thread 4 is not woken up, but how is that a deadlock?"

Eh, the most general definition of deadlock, which I use, is that a thread goes into a permanent wait when you expected it to be woken by something.

(I know that's not standard; the book definition of deadlock specifically refers to mutexes, but really any thread wait event is isomorphic to a mutex)

"More precisely, it gives you "atomic(notify_one_waiter) then atomic(remove_waiter)", not "atomic(notify_one_waiter_then_remove)", which would be a much nicer (and more intuitive) primitive. Correct?"

No, not exactly. My current implementation of notify_one actually does atomically remove the waiter. Which is what can mislead you into thinking that it should work.

The problem in the OR case is that because you have two different waitsets, you notify in waitsetX (which also removes) but that doesn't remove from waitsetY, so then the notify for Y might go to the one that already got the notify for X. If the notify could atomically remove from both waitsets, that might fix that case. (you can fix this by adding a shared variable to the "waiter" class that tracks whether it has received a notify or not, and don't notify guys who have already been notified by yourself or someone else).

In the semaphore case the problem is the time that you are in the waitset but not yet in a wait, when you might abort the wait due to the double-check.

That "limbo" period is crucial to making waitset work (this was discussed in detail in past posts) but it's also what causes the problem for when you want to be sure to wake the minimum number of threads.

Obviously in practice you would just put a mutex around the whole thing, which basically turns your waitset into a condition var and removes the limbo period.

If you like, this is a definition of why eventcount needs to be broadcast.

November 29, 2011 at 11:48 AM

Blogger IvyMike said...

On google, the "Verbatim" search (expand search tools, on the left) does OK.

It doesn't keep the "#" sign, but it does at least keep "StoreLoad" together, and the results seem a lot better.

November 29, 2011 at 1:37 PM

Blogger cbloom said...

The point of that aside is that I specifically want the #. The reason I put the # in my search is because I wanted the #. If I didn't want the # I wouldn't have put it in my search.

November 29, 2011 at 1:39 PM

Blogger Drawknob said...

// c was reloaded

Can you elaborate? How was it reloaded?

December 8, 2011 at 5:37 PM

Comment deleted

This comment has been removed by the author.

December 8, 2011 at 5:38 PM

You can use some HTML tags, such as <b>, <i>, <a>

This blog does not allow anonymous comments.

Comment moderation has been enabled. All comments must be approved by the blog author.

You will be asked to sign in after submitting your comment.