3 ms·
I've worked on projects that use threads before, but this week I started actually writing threaded code myself for the first time on a pet project (real time ra
by NickPollard 17y ago
I've worked on projects that use threads before, but this week I started actually writing threaded code myself for the first time on a pet project (real time ray tracer).
I understand much of the theory but without practice it's hard to know what to do, and so far my profiling has shown that my attempts at threading are slowing down the program, so I've still got a lot to learn.
- jbooth 17y agoTry to make the handoffs between threads as coarse-grained as possible. Passing data between threads means your thread acquires some lock, leaves the data there, then the other thread has to acquire the lock before getting the data -- both situations could involve a thread blocking and going to "blocked", then "runnable", then finally at some point in the future actually being executed and doing their work. If the tasks you're parcelling out are too fine grained and require too much communication, the scheduling overhead will outweigh the parallelism -- and you could be getting effectively singlethreaded performance plus overhead.