Game Development Reference
In-Depth Information
Chapter 6
Threading
There was a time in the 1980s when a computer did one and only one task at a time. In the times
of MS-DOS and CP/M, one could execute an application, exit from it back to the prompt, and then
invoke another. Additionally, Unix-like systems used the concept of multiuser usage, where each
user could run separate applications. While the OS can be multitasking—running several apps—each
application can perform different tasks. For example, downloading a file asynchronously while
playing music and updating the progress bar. To understand this concept better, we need to look
into these three important topics: processes, multitasking, and threads.
process is an instance of a computer program—a list of code-based
instructions—that is being executed, or run. Several processes can be
associated with the same program, and several instances of the same program
can be executed simultaneously; for example, each open window within a
browser is a process of its own.
A
Multitasking is a method that allows multiple processes to share processors and
other system resources. With multitasking, a CPU can switch between tasks
being executed without having to wait for one to finish. The way this works can
differ from system to system.
The smallest unit of processing that an operating system runs or executes is
called a thread . A process can have multiple threads, and the CPU can switch
between these threads to provide the perception of multiple threads running at
the same time.
Coroutines
Programming languages use subroutine or functions to call a set of instructions. The function or
subroutine is called and executed, and when it completes, it returns. A coroutine is a special type of
subroutine; like a subroutine or a function, it has an entry point, but it can be yielded (paused in the
middle) and then resumed from that point. A coroutine can be passed parameters at any time when
it is called, not just at the point of entry.
77
 
Search WWH ::




Custom Search