Thoughts on ThreadingPosted on February, 02 2016
'Threading' invokes a certain response in a programmers mind. To the layperson, 'Threading' (or "multithreading") implies that, given a running program, that program can run two or more pieces of code at the same time.
Multi-tasking and multi-processing dates back to the early 1970's and early 1980's, when computing required that all resources to be used in the most efficient way possible. The large, slow, and expensive computers at the time only existed in established institutions, where researchers would run computations on what were known as time-sharing systems. Time-sharing systems took a large 'mainframe' computer, and tied many users via teletype terminals where users would interact with the mainframe. It is this notion of multi-user systems that spawned the famous Unix systems, and the artifacts are found in the core design of any Unix-like system today. Due to these multi-user systems, time sharing algorithms have allowed the modern-day data centers to be an epicenter of distributed computations. Online services like Google, Amazon, Microsoft, and Facebook all take advantage of the idea of multi-user time-sharing systems to handle billions of requests without delay.
In the domain of individual applications, multi-threading arose when CPU's began incorporating multiple cores to simultaneously run two processes at the same time. In implementation, there are two types of threads that integrate with the operating system. One of the objectives a sane operating system must tackle is handling various processes that run on a given system. Under a process, the kernel organizes what are known as 'Kernel threads', which are running programs that share resources with other kernel threads which share the same process. For any process, there is at least one kernel thread. Scheduling of kernel threads are, by definition, handled by the operating system. Due to this, a program that implements kernel threads cannot control the behavior and scheduling of the threads it creates, which may not be fine-tuned for the applications needs. Besides kernel threads, there is another type of thread implementation that handles thread scheduling in user-space, as compared to kernel threads which are handled in kernel space. Userspace threading implementations take advantage of kernel threads to distribute jobs across available processors and implement a preferred scheduling scheme for the application at hand.
Modern computing wouldn't be where it is without the concept of juggling processes and threads over a shared piece of computing equipment.