4 Threads

Processes are not the only way to execute code concurrently. In fact, processes are quite resource hungry. This is because a parent/child process pair do not share any resources. All global variables, file descriptors, the heap and the stack are duplicated.

This also makes it somewhat difficult for processes to communicate. The most common method for processes to communicate is either via a pipe or a socket. This makes it clumsy for processes to share data structures. On the other hand, processes (not necessary a parent and a child) can easily communicate over a network for this reason.

If concurrent logic are tightly coupled (sharing complex data structures), then an alternative to processes should be considered. This, of course, refers to the concept of multi-threading.

 4.1 Roughly speaking, what is a thread?
 4.2 When to use processes and when to use threads?
 4.3 Linux PThreads