Threads and Semaphores Visualizer
Threads (pthread)
Semaphores (sem)
Main Thread
Running
Created Thread
Idle
Shared Memory
Heap (shared)
Global variables
Stack Thread 1
Stack Thread 2
Semaphore
1
Available
Critical Section (Shared Resource)
No thread inside
Thread 1
Waiting
Thread 2
Waiting
1
The main thread starts
▶
Play
▶▶
Next
↻
Restart
Key concepts:
pthread_create():
Creates a new thread that runs in parallel
pthread_join():
Waits for a thread to finish (like wait() for processes)
Shared memory:
Threads share the same heap
pthread_exit():
Ends a thread cleanly