pthread
美
英 
- 網(wǎng)絡(luò)線程示例;條件變量主要操作;線程模型
例句
I further tested this simple Pthread code on the PPE to see how it scales with an increasing number of threads.
我在PPE上進(jìn)一步測(cè)試了這個(gè)簡(jiǎn)單的Pthread代碼,以此了解隨著線程數(shù)量的增加它的性能變化情況。
As you can see, pthread_mutex_init accepts a pointer to an already-allocated region of memory to initialize as a mutex.
正如所示,pthread_mutex_init接受一個(gè)指針作為參數(shù)以初始化為互斥對(duì)象,該指針指向一塊已分配好的內(nèi)存區(qū)。
In other words, the system allocates at least 10MB of private storage for each pthread.
換言之,系統(tǒng)為每個(gè)pthread分配至少10MB的專用存儲(chǔ)。
This sounds a bit confusing, but the pthread example below will clarify how condition variables work.
這聽起來有點(diǎn)難以理解,下面的pthread例子會(huì)說明條件變量是怎么工作的。
Thus, PTHREAD_PROCESS_SHARED and interprocess POSIX synchronization primitives can be implemented and are now available.
這樣,PTHREAD_PROCESS_SHARED和進(jìn)程間POSIX同步原語可以被實(shí)現(xiàn),而且現(xiàn)在可用。
pthread -qthreaded or _r invocation mode Creates programs running in a multithreaded environment.
pthread-qthreaded或_r調(diào)用模式創(chuàng)建在多線程環(huán)境中運(yùn)行的程序
In Linux, pthread_cond_signal wakes up a thread waiting on a conditional variable.
在Linux中,pthread_cond_signal會(huì)喚醒等待某個(gè)條件變更的某個(gè)線程。
Futex (fast user space mutex) is done by the kernel on the thread ID upon pthread_join (for more on futex, please see Resources).
當(dāng)pthread_join發(fā)生時(shí)由內(nèi)核根據(jù)線程ID來完成Futex(fastuserspacemutex)。(要了解futex的更多信息,請(qǐng)參閱參考資料)。
POSIX provides locking and synchronization support through the pthread_mutex data type.
POSIX通過pthread_mutex數(shù)據(jù)類型提供鎖定和同步支持。
In Linux, the pthread_cancel method terminates execution of the thread identified by the specified threadId.
在Linux中,pthread_cancel可以終止由具體的threadId所標(biāo)識(shí)的線程的執(zhí)行。
Note that you've invoked pthread_cond_broadcast after releasing the mutex.
注意,在釋放互斥鎖之后調(diào)用pthread_cond_broadcast。
If the list were originally empty, you call pthread_cond_broadcast to post push data into the list.
如果列表原來是空的,就調(diào)用pthread_cond_broadcast以宣告列表中已經(jīng)添加了數(shù)據(jù)。
In libspe2, the operation is synchronous, so if you want to run a thread in the background, you have to make your own pthread calls.
在libspe2中,這個(gè)操作變成同步的了,因此您可能會(huì)希望在后臺(tái)運(yùn)行一個(gè)線程,并發(fā)出自己的pthread調(diào)用。
A POSIX API for creating a pthread_mutex lets the mutex implement the priority-inheritance protocol.
用于創(chuàng)建pthread_mutex的POSIXAPI使用互斥鎖來實(shí)現(xiàn)優(yōu)先級(jí)繼承協(xié)議。
If you need to block the calling thread for a specific time, then use the pthread_cond_timewait to block the thread.
如果您需要在指定的一段時(shí)間內(nèi)阻塞發(fā)出調(diào)用的線程,那么請(qǐng)使用pthread_cond_timewait來阻塞它。
pthread_mutexes can be created with different locking policies.
pthread_mutex可以使用不同的鎖定策略創(chuàng)建。
pthread_rwlock_rdlock may fail if the maximum number of read locks (implementation defined) for the lock has been exceeded.
如果超過了最大讀鎖數(shù)量(由實(shí)現(xiàn)定義),pthread_rwlock_rdlock可能會(huì)失敗。
This careful Pthread scheduling leads to much more deterministic and repeatable test runs.
這種仔細(xì)的Pthread調(diào)度方法使測(cè)試運(yùn)行的結(jié)果更加準(zhǔn)確,可重復(fù)性更高。
Table 1 above displays the pthread condition variable for synchronization between threads.
前面的表1給出了用于線程間同步的pthread條件變量。
You can further optimize this situation by using pthread_mutex_timedlock API, if your system supports it (see Resources).
如果系統(tǒng)支持的話,可以使用pthread_mutex_timedlockAPI進(jìn)一步優(yōu)化這個(gè)場(chǎng)景(見參考資料)。
Instead of providing an abstraction of logical SPUs, this interface is thread-oriented and behaves in a similar way to the pthread library.
這個(gè)接口并不是提供一個(gè)邏輯SPU的抽象,而是面向線程的,它的工作方式與pthread庫類似。
The linker complained of some missing pthreads-related exports.
鏈接器抱怨缺少與pthread相關(guān)的輸出。
Otherwise, it can be created statically when it is declared by a pthread_mutex_t variable.
或者,當(dāng)通過pthread_mutex_t變量聲明它的時(shí)候,可以靜態(tài)地創(chuàng)建它。
Meanwhile, you can use pthread_xxxx calls at any time after the thread has been created.
同時(shí),您在創(chuàng)建線程之后的任意時(shí)候都可以使用pthread_xxxx。
Linux pthread mutexes are supported by fast user-space mutexes, known as futexes.
快速用戶空間互斥(也被稱為futexes)支持Linuxpthread互斥鎖。
Immediately after unlocking the mutex, thread 2 calls the function pthread_cond_broadcast(&mycond).
在對(duì)互斥對(duì)象解鎖之后,2號(hào)線程會(huì)立即調(diào)用函數(shù)pthread_cond_broadcast(&mycond)。
With this background, let's look at the function pthread_cond_timedwait, which you use for the second check.
有了這些背景知識(shí),我們來看看pthread_cond_timedwait函數(shù),這個(gè)函數(shù)用于進(jìn)行第二個(gè)檢查。
While still holding the mutex lock, our thread will call pthread_cond_wait(&mycond, &mymutex).
鎖定互斥對(duì)象時(shí),線程將調(diào)用pthread_cond_wait(&mycond,&mymutex)。
Take care to invoke pthread_rwlock_unlock n times if there are n concurrent read locks for the lock.
如果有n個(gè)并發(fā)的讀鎖,一定要調(diào)用pthread_rwlock_unlockn次。
The POSIX lock type is a pthread_mutex.
POSIX鎖的類型為pthread_mutex。
If the reader thread is awakened before the timeout, the return value from pthread_cond_timedwait will be 0.
如果在超時(shí)之前讀線程被喚醒,pthread_cond_timedwait的返回值是0。
As a second argument, it can also accept an optional pthread_mutexattr_t pointer.
第二個(gè)參數(shù),可以接受一個(gè)可選的pthread_mutexattr_t指針。
A note on Pthreads scheduling and compiler optimization
關(guān)于Pthread調(diào)度和編譯器優(yōu)化的幾點(diǎn)說明