Important Notice: Our web hosting provider recently started charging us for additional visits, which was unexpected. In response, we're seeking donations. Depending on the situation, we may explore different monetization options for our Community and Expert Contributors. It's crucial to provide more returns for their expertise and offer more Expert Validated Answers or AI Validated Answers. Learn more about our hosting issue here.

How pthread_mutex_t is different from semaphore?

different semaphore
0
10 Posted

How pthread_mutex_t is different from semaphore?

0
10

The difference between a mutex and a semaphore is how the blocking is handled. Think of a semaphore as simply a counter. This counter is created in the kernel memory space, and is available to be accessed by multiple users and processes. This is useful in that you can have different users or applications, or multiple instances of the same application running that need to access the same resources. When they need to access the resource, the application will need to check the semaphore. The semaphore will be incremented (or decremented depending on the implementation). When the semaphore value reaches zero (usually) the resource is “available” and another process can increment/decrement the semaphore and use the resource, then set the semaphore back. A mutex (mutual exclusion) is generally used to block threads that are initiated by the same calling process. Same principle as a semaphore, but used to protect resources (including variables) in your multi-threaded app. So, for example, if

Related Questions

What is your question?

*Sadly, we had to bring back ads too. Hopefully more targeted.

Experts123