Hacker Newsnew | past | comments | ask | show | jobs | submitlogin
Multithreading for Dummies (science20.com)
9 points by ingve on Aug 16, 2023 | hide | past | favorite | 1 comment


> I looked at the screen in disbelief. Could it really be that easy? The whole thing would boil down to adding an #include command at the beginning of my source code, and then embed into functions the two parts that could be parallelized; a synchronization command would suffice to restore single-threading at the end of each fan-out.

Parallelization is good, but it still sounds like it runs synchronously, so all the rest of the threads are stuck waiting for the slowest one to join.

If you really want foolproof multithreading for dummies, write all your code around an event loop that sends your tasks to a thread pool backed by a message queue.

You can have your parent threads that glue everythhing together still be synchronous, but the critical sections of code should be executed asynchronously so the only threads being blocked are the parents waiting for the completion event containing the results.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: