Example: Parallelize Banking Database
- consider that we use the fork feature so that we can parallelize the banking transactions, there is an issue because when each of the updates occur, they occur in their local virtual memory space rather than updating the parent process information
- threading allows us to have the different processes to access the same namespace and virtual memory
Parallel Processing
- to consider the parallel processing approach we separate the logical control flow from all of the data within the process and thus, multiple logical instruction sets can occur within the same process
- each thread has its own log control flow
- each thread shares same code, data, and kernel context,
- each thread has its own stack for local variables
Logical View of Threads
- the threads associated with process form a pool of peers rather than having some sort of process tree
- two threads are concurrent if their flows overlap in time
- thread A and thread B are concurrently running on both of the processors
Threads vs. Processes
Similarity
- threads and processes each have their logical control flow
- each can run concurrently with others
- each is context switched → the kernel tells it what happens at what time to execute properly
The Differences
- threads share code and data
- threads are less expensive to create than processes
- creating the page table and reading / reaping all of the things are expensive operations
Posix Threads (Syntax)