Threads

Programming with concurrent processes is an old and well-understood practice, but it is rapidly falling out of favor, because a more efficient technique has been developed in recent years.

Remember that when a process undergoes a fork, it creates a copy of itself. Surely that's overkill, though. When you're reading a truly fascinating book and the telephone rings, you don't clone yourself so there can be one of you attending to the phone and the other attending to your reading. Instead you put your finger on the page so as not to lose your place, reach over with the other hand to grab the phone, and chatter politely (mm hmm, mm hmm), glancing back down at the book every chance you get. See how much reading you can still get done? And ...

Get Sams Teach Yourself Ruby in 21 Days now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.