Checkedthreads: bug-free shared memory parallelism
yosefk.com
yosefk.com
Does this hold for the following code:
for (j = 0; j < 3; j++) a = j % 2;
In both forward (0, 1, 2) and backward (2, 1, 0) order, the final value of a is 0. But with the j==1 loop running last, a becomes 1 instead.
* It does work in the sense of reordering every pair of instructions that could ever run in parallel.
* It doesn't work in the sense that results aren't changed; this is true for a lot of more likely programs - for instance, a+=arr[j], and many others.
Reordering every pair of independent instructions doesn't guarantee that you'll find all the races; that's why checkedthreads has the Valgrind tool. It does find a whole lot of bugs very quickly, and it's also needed for the Valgrind tool to actually cover all the races - but it's not sufficient by itself.
To find all the bugs using just event reordering, you'd need to try something closer to all possible way to interleave independent instructions and that's a boatload of orders...
You can, of course, run with more schedules (checkedthreads lets you do this using env CT_SCHED=shuffle CT_RAND_SEED=654 or some other number) and then more bugs would be found, but you quickly reach diminishing returns compared to just running instrumentation (especially because a lot of bugs are not found by such coarse-grain reordering at all, for example, anything involving accumulators, counters, thread-unsafe allocators, the settings of bits in bit masks, etc.)
It's working very smoothly for us, to the point where nobody is worried about parallelism bugs any more - but while it's basically the same approach, the code itself is new, so I could have new bugs in there as well.
Very cool (and practical!) project though.
The license doesn't need to be a specially-named file, though most people use something sensible like 'license.txt' or 'LICENSE'. For example, here's one of my in-progress hobby projects:
https://github.com/jack-pappas/fsharp-tools
The Apache 2.0 license is a "do whatever you want with it" license (i.e., a permissive license).
Since I got 3 different people asking for a license, I might as well find one. I'd like something really permissive that also lets you strip the thing and doesn't have to be at the top of every file and doesn't require to give credit... Something that lets you do whatever you want to.
Is all of the necessary work being offloaded to Valgrind?
The post does have an informal kind of "proof" (there are various degrees of "formality"...) where I cover the various cases.
What's "all of the necessary work"? You mean is there an overhead due to checking? I think very little - maybe you could count as overhead the fact that you can swap schedulers at run time, the cost here is a call through a function pointer. (I could have done it as a compile time option of course, I just don't think the tiny overhead is worth the rather large trouble to the user.)
(Disclaimer: my research is on safer parallel programming)