Staying Out of Trouble
As I pointed out at the opening of this chapter, dealing with multiple threads is one of those great power versus great responsibility situations. Programming with multiple threads opens up the possibility that you can keep all your CPU cores busy doing productive work. But multiple threads also means dealing with the headaches—and dangers—that come with trying to do more than one thing at a time.
So far in this chapter we have walked through some of the obvious threads fighting over resources problems, but threads come with some other, less obvious dangers. For example, threads are expensive: creating a new thread takes a long time, and each thread takes up a reasonable chunk of memory.
Thus if you just want to get ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access