Multithreading with ÃMQ
ÃMQ is perhaps the nicest way ever to write multithreaded (MT) applications. Whereas ÃMQ sockets require some readjustment if you are used to traditional sockets, ÃMQ multithreading will take everything you know about writing MT applications, throw it into a heap in the garden, pour gasoline over it, and set it alight. Itâs a rare book that deserves burning, but most books on concurrent programming do.
To make utterly perfect MT programs (and I mean that literally), we donât need mutexes, locks, or any other form of inter-thread communication except messages sent across ÃMQ sockets.
By âperfectâ MT programs, I mean code thatâs easy to write and understand, that works with the same design approach in any programming language and on any operating system, and that scales across any number of CPUs with zero wait states and no point of diminishing returns.
If youâve spent years learning tricks to make your MT code work at all, let alone rapidly, with locks and semaphores and critical sections, you will be disgusted when you realize it was all for nothing. If thereâs one lesson weâve learned from 30+ years of concurrent programming, it is: just donât share state. Itâs like two drunkards trying to share a beer. It doesnât matter if theyâre good buddies. Sooner or later, theyâre going to get into a fight. And the more drunkards you add to the table, the more they fight each other over the beer. The tragic majority of MT applications look ...
Get ZeroMQ 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.