Arg, sorry, I missed the `if (count == expected_value)` some lines below. 500k is good.
If you add a volatile variable to signal the 2nd thread that the work is done, then everything is good.