Search code examples
multithreadingmutexsemaphoresingle-threaded

Semaphores in a single thread


I was wondering whether it would ever make sense to use a mutex or semaphore when there is only one thread?.

Thanks for your help.


Solution

  • I design thread protection into my components because they are reusable and scalable components intended to work in any environment I can realistically anticipate. Many times they are initially used in a single thread environment. Often times the scope of the implementation expands to include more threads. Then I don't have to chase down resources to protect from the new access scenarios.