确定特定体系结构的变化,比如互斥锁定(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.
锁定互斥对象时,线程将调用 pthread_cond_wait(&mycond,&mymutex)。
While still holding the mutex lock, our thread will call pthread_cond_wait(&mycond,&mymutex).
它还允许您原子地(atomically)解除互斥的锁定,并等待条件变量,而不会有干涉其他线程的可能。
It also allows you to unlock the mutex and wait on the condition variable atomically, without the possible intervention of another thread.
互斥锁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.
当一个互斥锁被锁定后,它必须被解锁。
可以推测到,当线程试图锁定一个未加锁的互斥对象时,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.
占有这个惟一物体的过程就叫做锁定或者获得互斥量。
Once you have it, no one can take it away from you until you put it down. The process of picking up the unique object is called locking, or acquiring, the mutex.
函数pthread_cond_wait主要就是用于阻塞线程的,它有两个参数;第一个是一个指向条件变量的指针,第二个是一个锁定了的互斥量。
The function primarily used for this is pthread_cond_wait . It takes two arguments; the first is a pointer to a condition variable, and the second is a locked mutex.
主线程:锁定互斥量并增量threadcount。
您还可以使用 pthread_mutex_trylock()来测试某个互斥是否已经被锁定,而不需要真正 地去锁定它。
You can also use the pthread_mutex_trylock() to test whether a mutex is locked without actually blocking it.
最后,当一个线程从调用pthread_cond_wait而被唤醒时,要做的第一件事就是重新锁定它在最初调用时解锁的那个互斥量。
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.
为了帮助实现互斥锁分配和锁定时间的最小化,JVM管理一个全局锁缓存和一个单线程锁缓存,其中每个缓存包含了未分配的 pthread_mutex。
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.
同样地,当线程a正锁定互斥对象时,如果线程c试图锁定互斥对象的话,线程c也将临时进入睡眠状态。
Likewise, if thread "c" tries to lock the mutex while thread "a" is holding it, thread "c" will also be put to sleep temporarily.
应用推荐