Only one task may hold the mutex at a time, and only this task can unlock the mutex.
一次只能有一个任务持有互斥锁,并且只有这个任务可以解锁互斥锁。
The mutex kind can be set in two ways.
可以以两种方式设置互斥的类型。
The problem with a mutex-based approach.
基于互斥锁的方法的问题。
为什么要用互斥对象?
But you can also create a mutex dynamically.
但是还可以动态地创建互斥对象。
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.
这个方法允许您设置互斥信号量对象的相关属性。
However, if the mutex is locked this call won't block.
然而,如果互斥对象已锁定,这个调用也不会阻塞。
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)。
Also note that both condition variables use the same mutex.
还要注意,两个条件变量使用相同的互斥锁。
This structure can be used to set various mutex attributes.
这个结构可用来设置各种互斥对象属性。
This function gets a pointer to the mutex it is trying to lock.
这个函数会获得一个指向它正在尝试锁定的互斥的指针。
No two threads can have the same mutex locked at the same time.
两个线程不能同时对同一个互斥对象加锁。
Identifying architecture-specific changes such as mutex locking.
确定特定体系结构的变化,比如互斥锁定(mutex locking)。
The mutex is simple, but there are some rules you should remember.
互斥锁很简单,但是有一些规则必须牢记。
Pthread_mutex_lock accepts a single pointer to a mutex to lock.
pthread _ mutex_lock接受一个指向互斥对象的指针作为参数以将其锁定。
The data structure is in effect "frozen" until the mutex is unlocked.
那个数据结构实际上是“冻结”了,直到互斥对象被解锁为止。
In either case, when control is returned, the caller holds the mutex.
无论在哪种情形中,当控制被返回时,调用者将持有互斥锁。
Here is another Win32 sample code to acquire mutex between processes.
这里是获得进程间互斥的另一Win32示例代码。
If the mutex is held (locked), then one is returned; otherwise, zero.
如果互斥锁被持有(锁定),那么就会返回1;否则,返回0。
This way, the change to add mutex code only has to happen in one place.
这样做使增加互斥代码时只需要在一个子程序中进行改动。
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.
锁定操作的设置涉及分配一个预先锁定的互斥锁。
Here's the sample code for creating a mutex (see Listings 6 and 7 below).
这里是创建互斥的示例代码(见下面的6和7)。
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.
如果进行调用的线程并不拥有那个互斥对象,则这个调用可能会失败。
应用推荐