确定特定体系结构的变化,比如互斥锁定(mutex locking)。
Identifying architecture-specific changes such as mutex locking.
在阻塞的情况下,托管任务将继续持有其在调度期间获得的所有共享资源(例如,存储资源、任务级别的资源和互斥锁定)。
While blocked, the managed task continues to hold any Shared resources it acquired during the course of its dispatch (for example, storage resources, task-level resources, and mutex locks).
那个错误不是归咎于被锁定的互斥。
这个函数会获得一个指向它正在尝试锁定的互斥的指针。
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.
当互斥被锁定或者发生错误时,函数返回。
The function returns when the mutex is locked, or if an error occurred.
当线程正在做其它事情的时候(由于互斥对象当前是锁定的),如果希望锁定互斥对象,这个调用就相当方便。
This call is handy when you want to lock a mutex while your thread is doing something else (because the mutex is currently locked).
如果另一个线程锁定了那个互斥,则pthread _ mutex _ trylock将不会阻塞。
If another thread locks the mutex, the pthread_mutex_trylock will not block.
这个例程做了一些新的工作;它锁定一个叫做count _ mutex的互斥量。
This routine does something new; it locks a mutex called, creatively enough, count_mutex.
如果互斥锁被持有(锁定),那么就会返回1;否则,返回0。
If the mutex is held (locked), then one is returned; otherwise, zero.
调用 pthread_mutex_trylock() 时将尝试锁定互斥对象。
When you call pthread_mutex_trylock() you'll attempt to lock the mutex.
锁定互斥对象时,线程将调用 pthread_cond_wait(&mycond,&mymutex)。
While still holding the mutex lock, our thread will call pthread_cond_wait(&mycond,&mymutex).
一旦 pthread_cond_wait()锁定了互斥对象,那么它将返回并允许1 号线程继续执行。
Once pthread_cond_wait() has the lock, it will then return and allow thread 1 to continue execution.
它还允许您原子地(atomically)解除互斥的锁定,并等待条件变量,而不会有干涉其他线程的可能。
It also allows you to unlock the mutex and wait on the condition variable atomically, without the possible intervention of another thread.
如果线程2要运行,它就要锁定count _ mutex,而这个互斥量已经被线程1占有了。
If thread two runs, it'll want to lock count_mutex, which is held by thread one.
如果线程1要运行,它就要锁定rand _ mutex,可是这个互斥量已经被线程2阻塞了。
If thread one runs, it'll want to lock rand_mutex, which is held by thread two.
互斥锁api提供了5个函数:其中3个用于锁定,一个用于解锁,另一个用于测试互斥锁。
The mutex API provides five functions: three are used for locking, one for unlocking, and another for testing a mutex.
如果线程a试图锁定一个互斥对象,而此时线程b已锁定了同一个互斥对象时,线程a就将进入睡眠状态。
If thread "a" tries to lock a mutex while thread "b" has the same mutex locked, thread "a" goes to sleep.
锁定操作的设置涉及分配一个预先锁定的互斥锁。
The setup for a lock operation involves allocation of a prelocked mutex.
如果碰巧已经锁定了互斥对象,调用者将进入睡眠状态。
If the mutex already happens to be locked, the caller will go to sleep.
当一个互斥锁被锁定后,它必须被解锁。
如果可能,在设计程序时决不要锁定一个已经锁定的互斥量。
If possible, just design your program never to re-lock a mutex it already has.
可以推测到,当线程试图锁定一个未加锁的互斥对象时,POSI x线程库将同意锁定,而不会使线程进入睡眠状态。
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.
在两个级别上执行锁定(见清单7):链表有一个读写锁,各个节点包含一个互斥锁。
Locking occurs on two levels (see Listing 7) : The list has a read-write lock, while individual nodes contain a mutex.
它还会检查互斥在那个时刻是不是解除锁定的(见清单9)。
It also checks whether the mutex is unlocked at that time (see Listing 9).
这个坏程序的开发者起初的想法是好的,即只在真正需要使用之前才锁定这些互斥量,但是他却直到运行结束才解锁。
The hapless developer of this monstrosity came up with the clever idea of only locking things when they are actually about to be used, but deferring unlocking until the end of a run.
非争用的解锁操作将一个锁定的互斥锁返回给线程锁定缓存。
Uncontested unlock operations return a locked mutex to the thread lock cache.
图中,锁定了互斥对象的线程能够存取复杂的数据结构,而不必担心同时会有其它线程干扰。
The thread in this image that has the mutex locked gets to access the complex data structure without worrying about having other threads mess with it at the same time.
应用推荐