一次只能有一个任务持有互斥锁,并且只有这个任务可以解锁互斥锁。
Only one task may hold the mutex at a time, and only this task can unlock the mutex.
这将创建一个新的互斥锁并初始化其结构。
此类型的互斥锁可提供错误检查。
当一个互斥锁被锁定后,它必须被解锁。
在内核中可以使用互斥锁来实现信号量行为。
Mutexes are available in the kernel as a way to accomplish semaphore behavior.
锁定操作的设置涉及分配一个预先锁定的互斥锁。
The setup for a lock operation involves allocation of a prelocked mutex.
可能因为分配的时间片结束,持有互斥锁的线程被取消调度。
A thread holding a mutex can be de-scheduled, perhaps because it was the end of its time-slice.
因此,最后两个读线程都等待条件变量,互斥锁没有被锁住。
Therefore, at the end of it all, you now have two reader threads, both waiting on the condition variable, and the mutex is unlocked.
队列类的构造函数和析构函数负责创建和销毁互斥锁,见清单1。
The constructor and destructor of the queue class are responsible for the creation and destruction of the mutex, as shown in Listing 1.
如果锁可用,则获取锁,执行互斥锁动作,然后释放锁。
When the lock is available, it is taken, the mutually-exclusive action is performed, and then the lock is released.
尝试解除由其他线程锁定的互斥锁会产生不确定的行为。
Attempting to unlock a mutex locked by a different thread results in undefined behavior.
如果在读线程能够获得互斥锁之前发生了超时,那么不需要进行处理。
If the timeout has occurred before the reader thread could acquire the mutex, then no processing need be done.
这个互斥锁的状态立即去掉标记,其他等待的线程被阻止。
The state of the mutex is immediately reset to not signaled so any other waiting threads remain blocked.
非争用的解锁操作将一个锁定的互斥锁返回给线程锁定缓存。
Uncontested unlock operations return a locked mutex to the thread lock cache.
内核互斥锁是在原子api之上实现的,但这对于内核用户是不可见的。
The kernel mutex is implemented on top of the atomic API, though this is not visible to the kernel user.
这对于等待同一互斥锁的其他线程有不利影响,因为等待时间现在会更长。
For other threads waiting on the same mutex, this has a negative effect, because the wait time is now even longer.
如果到超时时间段结束时还没有被唤醒,读线程需要唤醒自身并释放互斥锁。
If not awake otherwise, at the end of the timeout, the reader needs to wake itself up and release the mutex.
可以通过DEFINE _ mutex宏使用一个操作创建和初始化互斥锁。
You create and initialize a mutex in one operation through the DEFINE_MUTEX macro.
更好的做法是定义另一个方法,它接收一系列整数,只获取并释放互斥锁一次。
A far better approach would be to define another method that accepts a list of integers and acquire and release the mutex only once.
这个调用在互斥锁可用时返回,否则,在互斥锁锁可用之前它将休眠。
This call returns if the mutex is available; otherwise, it sleeps until the mutex is available.
这个中间件在请求开始之前加一个互斥锁,在请求结束之后解开这个锁。
The middleware locks a mutex at the beginning of the request, and unlocks the mutex when the request finishes.
多个控制线程可以同时在队列中添加数据或删除数据,所以需要用互斥锁对象管理同步。
Multiple threads of control can simultaneously try to push data to the queue or remove data, so you need a mutex object to manage the synchronization.
现在只剩下两个次要的任务 ——初始化互斥锁和启动线程运行可上传的文件的列表。
This just leaves us with a couple of minor bookkeeping tasks -- initializing the mutex and starting a thread to run through the list of uploadable files.
存放数据的时候,他先要获得互斥锁,再往总线上写数据,最后再释放互斥锁。
When publishing its data, it would acquire a mutex, do writes to the bus, and release the mutex.
这么做会唤醒所有等待条件变量_ cond的读线程;读线程现在隐式地争夺互斥锁。
Doing so awakens all the reader threads that were waiting on the condition variable _cond; the reader threads now implicitly compete for the mutex lock as and when it is released.
显然,把数据放到队列中就像是把数据添加到列表中,必须使用互斥锁保护这个操作。
Clearly, pushing data into the queue is akin to appending data to the list, and this operation must be guarded by mutex locks.
在两个级别上执行锁定(见清单7):链表有一个读写锁,各个节点包含一个互斥锁。
Locking occurs on two levels (see Listing 7) : The list has a read-write lock, while individual nodes contain a mutex.
操作系统调度程序决定哪个线程获得对互斥锁的控制权—通常,等待时间最长的读线程先读取数据。
The operating system scheduler determines which thread gets control of the mutex next-typically, the reader thread that has waited the longest gets to read the data first.
当这个线程完成了,它必须改变互斥锁为标记状态,以便其他的进程可以访问这些资源。
When the thread is finished with the resource, it must set the state of the mutex to signaled to allow other threads to access the resource.
互斥锁api提供了5个函数:其中3个用于锁定,一个用于解锁,另一个用于测试互斥锁。
The mutex API provides five functions: three are used for locking, one for unlocking, and another for testing a mutex.
应用推荐