pthreads的互斥VS信号 [英] pthreads mutex vs semaphore

查看:203
本文介绍了pthreads的互斥VS信号的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

什么是由pthread库提供的信号量和互斥的区别?

What is the difference between semaphores and mutex provided by pthread library ?

推荐答案

信号灯有一个同步计数器和互斥的只是二进制(真/假)。

semaphores have a synchronized counter and mutex's are just binary (true / false).

一个信号经常被用来作为回答一个资源有多少个元素一个明确的机制,都在使用 - 例如,一个对象,再presents n个工作线程可能会使用一个信号量来算的工作线程是如何提供

A semaphore is often used as a definitive mechanism for answering how many elements of a resource are in use -- e.g., an object that represents n worker threads might use a semaphore to count how many worker threads are available.

事实是,你可以通过一个由互斥体同步的INT重新present一个信号。

Truth is you can represent a semaphore by an INT that is synchronized by a mutex.

这篇关于pthreads的互斥VS信号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆