Lec23 Multi Threaded Programming (Arif Butt @ PUCIT)
Lec31 Synchronization among Threads (Arif Butt @ PUCIT)
Multi Threaded Programming
- Sequential Programming vs Concurrent/Parallel Programming
- 3 way to achieve concurrency
- Multiple single threaded processes → lot of memory and time required for process creation
- Multiple threads with a single processes
- Single process multiple events
- Thread is an execution context that is independently scheduled, but shares a single addresses space with other threads of the same process
Similar to process:
- states → new, ready, running, block, terminated
- Only one thread in running state (single CPU)
- can create a child
Diferrences
- no automatic protection in threads
- threads executes within the same address space
share code/data/file
has they on registers and stack
- memset
- printf
- malloc
- free
- write