pthread

pthread

 英

  • 网络线程示例;条件变量主要操作;线程模型

例句

I further tested this simple Pthread code on the PPE to see how it scales with an increasing number of threads.

PPE进一步测试这个简单Pthread代码了解随着线程数量增加性能变化情况

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接受一个指针作为参数初始化为互斥对象指针指向一块分配内存

In other words, the system allocates at least 10MB of private storage for each pthread.

换言之系统每个pthread分配至少10MB专用存储

This sounds a bit confusing, but the pthread example below will clarify how condition variables work.

听起来有点难以理解下面pthread例子说明条件变量怎么工作

Thus, PTHREAD_PROCESS_SHARED and interprocess POSIX synchronization primitives can be implemented and are now available.

这样,PTHREAD_PROCESS_SHARED进程间POSIX同步原语可以实现而且现在可用

pthread -qthreaded or _r invocation mode Creates programs running in a multithreaded environment.

pthread-qthreaded_r调用模式创建多线程环境运行程序

In Linux, pthread_cond_signal wakes up a thread waiting on a conditional variable.

Linux,pthread_cond_signal唤醒等待某个条件变更某个线程

Futex (fast user space mutex) is done by the kernel on the thread ID upon pthread_join (for more on futex, please see Resources).

pthread_join发生内核根据线程ID完成Futexfastuserspacemutex)。(了解futex更多信息参阅参考资料)。

POSIX provides locking and synchronization support through the pthread_mutex data type.

POSIX通过pthread_mutex数据类型提供锁定同步支持

In Linux, the pthread_cancel method terminates execution of the thread identified by the specified threadId.

Linux,pthread_cancel可以终止具体threadId标识线程执行

Note that you've invoked pthread_cond_broadcast after releasing the mutex.

注意释放互斥之后调用pthread_cond_broadcast。

If the list were originally empty, you call pthread_cond_broadcast to post push data into the list.

如果列表原来调用pthread_cond_broadcast宣告列表已经添加数据

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这个操作变成同步因此可能希望后台运行线程发出自己pthread调用

A POSIX API for creating a pthread_mutex lets the mutex implement the priority-inheritance protocol.

用于创建pthread_mutexPOSIXAPI使用互斥实现优先继承协议

If you need to block the calling thread for a specific time, then use the pthread_cond_timewait to block the thread.

如果需要指定一段时间阻塞发出调用线程那么使用pthread_cond_timewait阻塞

pthread_mutexes can be created with different locking policies.

pthread_mutex可以使用不同锁定策略创建

pthread_rwlock_rdlock may fail if the maximum number of read locks (implementation defined) for the lock has been exceeded.

如果超过最大数量实现定义),pthread_rwlock_rdlock可能失败

This careful Pthread scheduling leads to much more deterministic and repeatable test runs.

这种仔细Pthread调度方法使测试运行结果更加准确可重复

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).

如果系统支持的话可以使用pthread_mutex_timedlockAPI进一步优化这个场景参考资料)。

Instead of providing an abstraction of logical SPUs, this interface is thread-oriented and behaves in a similar way to the pthread library.

这个接口并不是提供一个逻辑SPU抽象而是面向线程工作方式pthread类似

The linker complained of some missing pthreads-related exports.

链接器抱怨缺少pthread相关输出

Otherwise, it can be created statically when it is declared by a pthread_mutex_t variable.

或者通过pthread_mutex_t变量声明时候可以静态地创建

Meanwhile, you can use pthread_xxxx calls at any time after the thread has been created.

同时创建线程之后任意时候可以使用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).

互斥对象之后,2号线立即调用函数pthread_cond_broadcast(&mycond)。

With this background, let's look at the function pthread_cond_timedwait, which you use for the second check.

这些背景知识我们来看看pthread_cond_timedwait函数这个函数用于进行第二检查

While still holding the mutex lock, our thread will call pthread_cond_wait(&mycond, &mymutex).

锁定互斥对象线程调用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并发一定调用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.

如果超时之前线程唤醒,pthread_cond_timedwait返回0。

As a second argument, it can also accept an optional pthread_mutexattr_t pointer.

第二参数可以接受一个pthread_mutexattr_t指针

A note on Pthreads scheduling and compiler optimization

关于Pthread调度编译优化说明