Full Disclosure mailing list archives
Re: [Code-Crunchers] a simple race condition and how you'd solve it
From: Valdis.Kletnieks () vt edu
Date: Thu, 02 Jul 2009 22:04:26 -0400
On Fri, 03 Jul 2009 11:01:34 +1000, silky said:
Basically, you just need to check if you should still be computing, and, at the end of computation, if your data is still "wanted".
All that does is push the race condition around. You *still* need to do some sort of locking around the tail end. This is still racy: if (update_still_wanted) { stash_my_update(); update_still_wanted = false; } (Admittedly, not *as* racy, especially if you move the assignment first. But that's still racy enough to actually *trip* on occasion - this sort of bug is actually found at least once a month in the Linux kernel in some device driver or other...) And to be honest - the "best" way of fixing this is *really* going to depend on the relative weight of locking (which can be *very* different if you have 2 threads on 2 CPUs, or 4096 threads on a 4096-core monster, or are split across systems possibly in different countries connected by a high or maybe low speed network), and how much effort goes into the computation, and how much correctness matters - for some cases, you *really* want "first to finish" (possibly due to side effects of the computation), others "any complete answer" is good enough, etc..
Attachment:
_bin
Description:
_______________________________________________ Full-Disclosure - We believe in it. Charter: http://lists.grok.org.uk/full-disclosure-charter.html Hosted and sponsored by Secunia - http://secunia.com/
Current thread:
- a simple race condition and how you'd solve it Gadi Evron (Jul 03)
- Re: [Code-Crunchers] a simple race condition and how you'd solve it silky (Jul 02)
- Re: [Code-Crunchers] a simple race condition and how you'd solve it Valdis . Kletnieks (Jul 02)
- Re: [Code-Crunchers] a simple race condition and how you'd solve it Phani (Jul 02)
- Re: [Code-Crunchers] a simple race condition and how you'd solve it Florian Weimer (Jul 08)
- Re: [Code-Crunchers] a simple race condition and how you'd solve it Valdis . Kletnieks (Jul 02)
- Re: [Code-Crunchers] a simple race condition and how you'd solve it silky (Jul 02)