Programming Interviews Exposed: Secrets to Landing Your Next Job, Second Edition
by John Mongan, Noah Suojanen, Eric Giguère
Chapter 8. Concurrency
Not that long ago, it wasn't unusual for programs to have a single thread of execution, even if they were running on a multithreading system. Even today, code you write for an application or Web server tends to be single-threaded, even if the server itself is multithreaded. Why? Because multithreaded programming (often referred to as concurrency) is hard to do correctly, even when the programming language directly supports it. The incorrect use of threads can easily halt your program's execution or corrupt its data.
However, if you're writing applications with a graphical user interface or that perform lengthy I/O operations, chances are good that you'll need to do some of the work using a background thread or two. Even JavaScript programmers doing AJAX-style programming encounter threading issues — even though neither the language nor the standard libraries explicitly support multithreading — because the Web server responses are processed asynchronously, and hence the JavaScript that runs to process the response possibly accesses data used by other parts of the application. That's why good programmers take the time to learn how to write multithreaded programs correctly.
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