The calls act as a warning to other threads to go to sleep and wait their turn for the mutex lock.
这两个函数调用的作用就是警告其它线程,要它们继续睡眠并等待轮到它们对互斥对象加锁。
While still holding the mutex lock, our thread will call pthread_cond_wait(&mycond,&mymutex).
锁定互斥对象时,线程将调用 pthread_cond_wait(&mycond,&mymutex)。
If thread "a" tries to lock a mutex while thread "b" has the same mutex locked, thread "a" goes to sleep.
如果线程a试图锁定一个互斥对象,而此时线程b已锁定了同一个互斥对象时,线程a就将进入睡眠状态。
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.
这么做会唤醒所有等待条件变量_ cond的读线程;读线程现在隐式地争夺互斥锁。
This function gets a pointer to the mutex it is trying to lock.
这个函数会获得一个指向它正在尝试锁定的互斥的指针。
Your code could repeatedly lock and unlock the mutex, checking for any changes to the value.
代码可以反复对互斥对象锁定和解锁,以检查值的任何变化。
Otherwise, you can use the "recursive" mutex type, which allows the holder of the lock to lock the same mutex multiple times.
另外,您还可以使用“递归”类型的互斥量,这种互斥量允许对同一个互斥量锁定多次。
Locking occurs on two levels (see Listing 7) : The list has a read-write lock, while individual nodes contain a mutex.
在两个级别上执行锁定(见清单7):链表有一个读写锁,各个节点包含一个互斥锁。
Because you're sharing the same mutex for push and pop operations, the data-read speed is somewhat compromised as writer threads access the lock.
因为添加和取出数据操作使用相同的互斥锁,所以读取数据的速度会影响写数据的线程访问锁。
Uncontested unlock operations return a locked mutex to the thread lock cache.
非争用的解锁操作将一个锁定的互斥锁返回给线程锁定缓存。
This call is handy when you want to lock a mutex while your thread is doing something else (because the mutex is currently locked).
当线程正在做其它事情的时候(由于互斥对象当前是锁定的),如果希望锁定互斥对象,这个调用就相当方便。
Main thread: Lock mutex and increment threadcount.
主线程:锁定互斥量并增量threadcount。
To help minimize mutex allocation and locking time, the JVM manages a global lock cache and a per-thread lock cache where each cache contains unallocated pthread_mutexes.
为了帮助实现互斥锁分配和锁定时间的最小化,JVM管理一个全局锁缓存和一个单线程锁缓存,其中每个缓存包含了未分配的 pthread_mutex。
The first function, mutex_trylock, is used in situations where you want the lock immediately or you want control to be returned to you if the mutex is not available.
在需要立即锁定以及希望在互斥锁不可用时掌握控制的情形下,可以使用第一个函数mutex _ trylock。
And you should never unlock a mutex that you don't hold a lock for (otherwise, the pthread_mutex_unlock call will fail with a non-zero EPERM return value).
并且绝对不要对您未保持锁的互斥对象进行解锁操作(否则,pthread _ mutex_unlock调用将失败并带一个非零的eperm返回值)。
The setup for a lock operation involves allocation of a prelocked mutex.
锁定操作的设置涉及分配一个预先锁定的互斥锁。
If the mutex is currently unlocked you'll get the lock, and this function will return zero.
如果互斥对象当前处于解锁状态,那么您将获得该锁并且函数将返回零。
As you may have guessed, the POSIX threads library will grant a lock without having put the thread to sleep at all if a thread tries to lock an unlocked mutex.
可以推测到,当线程试图锁定一个未加锁的互斥对象时,POSI x线程库将同意锁定,而不会使线程进入睡眠状态。
Finally, the first thing any thread tries to do when waking up from pthread_cond_wait is re-lock the mutex it unlocked when initially called.
最后,当一个线程从调用pthread_cond_wait而被唤醒时,要做的第一件事就是重新锁定它在最初调用时解锁的那个互斥量。
Likewise, if thread "c" tries to lock the mutex while thread "a" is holding it, thread "c" will also be put to sleep temporarily.
同样地,当线程a正锁定互斥对象时,如果线程c试图锁定互斥对象的话,线程c也将临时进入睡眠状态。
Pthread_mutex_lock accepts a single pointer to a mutex to lock.
pthread _ mutex_lock接受一个指向互斥对象的指针作为参数以将其锁定。
Buffer acquisition is managed through the use of latches, known as mutex, and lock-access information.
缓冲区的获取是通过使用锁存器(latch)和锁访问信息来管理的,该锁存器称作 mutex。
A thread attempting to re lock this mutex without first unlocking it shall return with an error.
如果线程在不首先解除锁定互斥锁的情况下尝试重新锁定该互斥锁,则会返回错误。
A thread attempting to re lock this mutex without first unlocking it shall deadlock.
如果线程在不首先解除互斥锁的情况下尝试重新锁定该互斥锁,则会产生死锁。
This could happen, for instance, if atomic CPU instruction is used to implement a mutex (as in "lock-free" algorithms).
这可能发生,例如,如果原子cpu指令是用来实现互斥(如无锁定算法)。
This could happen, for instance, if atomic CPU instruction is used to implement a mutex (as in "lock-free" algorithms).
这可能发生,例如,如果原子cpu指令是用来实现互斥(如无锁定算法)。
应用推荐