How to test multiple threads without sleep
Earlier in this chapter, in the The need to justify multiple threads section, I mentioned that you should try to do as much work as possible with single threads. We’re going to follow this advice now. In the current request handling for the calculate request, the code creates a thread that does a simple calculation, like this:
std::thread calcThread([calcIndex] ()
{
calculations[calcIndex].setData(true, 100, 50);
});
Okay, maybe a simple calculation is the wrong way to describe what the thread does. The thread sets the result to a hardcoded value. We know this is temporary code and that we’ll need to change the code to multiply the seed value by 10
, which is what the tests expect.
Where should the calculation...