Only one task may hold the mutex at a time, and only this task can unlock the mutex.
一次只能有一个任务持有互斥锁,并且只有这个任务可以解锁互斥锁。
After a mutex is locked, it must be unlocked.
当一个互斥锁被锁定后,它必须被解锁。
Using a mutex ensures that this doesn't happen.
使用互斥对象能够保证这种情形不会发生。
This method allows you to set mutex object attributes.
这个方法允许您设置互斥信号量对象的相关属性。
Listing 3 illustrates a static way of setting a mutex.
清单3介绍了设置互斥的静态方法。
This creates a new mutex and initializes the structure.
这将创建一个新的互斥锁并初始化其结构。
A mutex is unlocked with the function (see Listing 5).
使用下面的函数解开对互斥的锁定(见清单5)。
This function gets a pointer to the mutex it is trying to lock.
这个函数会获得一个指向它正在尝试锁定的互斥的指针。
Identifying architecture-specific changes such as mutex locking.
确定特定体系结构的变化,比如互斥锁定(mutex locking)。
Pthread_mutex_lock accepts a single pointer to a mutex to lock.
pthread _ mutex_lock接受一个指向互斥对象的指针作为参数以将其锁定。
Here is another Win32 sample code to acquire mutex between processes.
这里是获得进程间互斥的另一Win32示例代码。
If the mutex already happens to be locked, the caller will go to sleep.
如果碰巧已经锁定了互斥对象,调用者将进入睡眠状态。
The function returns when the mutex is locked, or if an error occurred.
当互斥被锁定或者发生错误时,函数返回。
The setup for a lock operation involves allocation of a prelocked mutex.
锁定操作的设置涉及分配一个预先锁定的互斥锁。
The mutex object must be declared; once declared, it must be initialized.
互斥量对象必须先被声明;声明后还必须初始化。
This call might fail if the calling thread does not own the mutex object.
如果进行调用的线程并不拥有那个互斥对象,则这个调用可能会失败。
If the calling thread has no ownership of this mutex, this function fails.
如果调用线程并不拥有这个互斥信号量,那么这个函数的执行将会失败。
It also checks whether the mutex is unlocked at that time (see Listing 9).
它还会检查互斥在那个时刻是不是解除锁定的(见清单9)。
Another way of setting the mutex kind is by using a mutex attribute object.
设置互斥的另一种方式是使用互斥属性对象。
Uncontested unlock operations return a locked mutex to the thread lock cache.
非争用的解锁操作将一个锁定的互斥锁返回给线程锁定缓存。
If another thread locks the mutex, the pthread_mutex_trylock will not block.
如果另一个线程锁定了那个互斥,则pthread _ mutex _ trylock将不会阻塞。
An equivalent Linux sample code to acquire mutex within a process (see Listing 15).
相应的获得进程内互斥的Linux示例代码(见清单15)。
Here is the Win32 sample code to acquire a mutex within a process (see Listing 14).
这里是获得进程内互斥的Win32示例代码(见listing14)。
So, let's say we go ahead and add a mutex that surrounds the random number generator.
所以,让我们更进一步,在产生随机数的地方加一个互斥量。
Mutexes have names, and only one mutex of a given name can exist on a machine at a time.
互斥有名称,并且,一个给定名称的互斥在同一机器上同一时刻只能存在一个。
This routine does something new; it locks a mutex called, creatively enough, count_mutex.
这个例程做了一些新的工作;它锁定一个叫做count _ mutex的互斥量。
When invoked, pthread_cond_wait unlocks the mutex and then pauses execution of its thread.
当pthread_cond_wait被调用后,它解锁互斥量并停止线程的执行。
If the mutex is currently unlocked you'll get the lock, and this function will return zero.
如果互斥对象当前处于解锁状态,那么您将获得该锁并且函数将返回零。
Your code could repeatedly lock and unlock the mutex, checking for any changes to the value.
代码可以反复对互斥对象锁定和解锁,以检查值的任何变化。
While still holding the mutex lock, our thread will call pthread_cond_wait(&mycond,&mymutex).
锁定互斥对象时,线程将调用 pthread_cond_wait(&mycond,&mymutex)。
应用推荐