Day58 - POSIX Semaphore IPC¶
Objective¶
Learn:
- POSIX named semaphore
- producer / consumer synchronization
- shared memory queue
- ring buffer
- process-shared pthread mutex
Lab 1 - Basic Semaphore¶
Build¶
Run waiter¶
Terminal 1:
Run poster¶
Terminal 2:
Expected:
Lab 2 - sem_trywait()¶
Expected:
Lab 3 - sem_timedwait()¶
Expected:
Lab 4 - Shared Memory Producer/Consumer¶
Cleanup old resources¶
Start consumer¶
Terminal 1:
Start producer¶
Terminal 2:
Expected:
Lab 5 - Ring Buffer Queue¶
Verify multiple messages are preserved¶
Terminal 2:
Expected:
Lab 6 - Queue Full Test¶
Terminal 2:
Expected:
- producer blocks on empty semaphore
- queue does not overwrite unread data
Lab 7 - Multi Producer Test¶
Terminal 2:
Terminal 3:
Expected:
- queue remains consistent
- no corruption
- consumer receives ordered sequence numbers
Key Learning Points¶
Semaphore¶
Provides:
- synchronization
- resource counting
Does NOT provide:
- shared data protection
Mutex¶
Provides:
- critical section protection
- queue consistency
Shared Memory¶
Provides:
- actual data transport