sawyl: (Default)
[personal profile] sawyl
Today's lesson: don't make groundless assumptions. This morning, I spent the best part of an hour trying to determine why one of my programs was taking 20 seconds longer than expected to spin down once all the worker threads had completed. I initially assumed that, because the delay matched the time-out I'd passed to select(), the problem was due to the threads waiting on output from one of their task, so I instrumented the code in an attempt to prove that some bits of work were taking longer than others.

The profiling information showed the exact opposite of my expectations: the threads were doing exactly the same amount of work and, once their work was done, paused for the time-out period and then barriered with the main program. When I looked closer I noticed that I'd actually used my time-out in two places: once in the select() call and once in the call to Queue.get(), in order to prevent the threads from spin-waiting on locks in the work queue. Suddenly, it all made sense: the threads had exhausted the work in the queue, but were forced to wait for time-out seconds until the queue returned with a Queue.Empty exception, at which point they were able to re-join the main thread.

If only I hadn't assumed that the problem was with select and instead remembered that I'd used the same time-out for the work queue, I'd have saved myself an hour. Still, it was only an hour and what else was I going to do with the time? I'd only have wasted it staring out of the window.

Profile

sawyl: (Default)
sawyl

August 2018

S M T W T F S
   123 4
5 6 7 8910 11
12131415161718
192021222324 25
262728293031 

Most Popular Tags

Style Credit

Expand Cut Tags

No cut tags
Page generated Feb. 5th, 2026 01:16 pm
Powered by Dreamwidth Studios