Semaphores in one thread

I was wondering if a mutex or semaphore can be used if there is only one thread?

Thank you for your help.

+3
source share
6 answers

I design thread protection in my components because they are reusable and scalable components designed to work in any environment that I can really expect. Many times they are initially used in a single-thread environment. Often, implementation scales expand to include more threads. Then I do not need to chase resources to protect against new access scenarios.

+4
source

Mutex , Mutex , . , Mutex .

+1

, , , , . , ( ).

+1

. , . , .

+1

system-wide semaphores ( ) inter-process communication.

You can signal from a single-threaded process to another single-threaded process using acquire()/release()-ing for a semaphore with a name, for example.

+1
source

In case the environment supports system interrupts, it adds non-linear behavior. A semaphore can be used to sleep in the main thread until an interrupt is triggered.

+1
source

Source: https://habr.com/ru/post/1751086/


All Articles