Solaris线程函数与读写锁的深入解析
1. 独特的Solaris线程函数
Solaris提供了一些独特的线程函数,主要用于线程执行的暂停和恢复。
1.1 暂停线程执行
thr_suspend(3C)函数可立即暂停由target_thread指定的线程的执行。调用成功后,被暂停的线程将停止执行。不过,使用该函数时需格外小心,因为它在暂停目标线程时不会考虑该线程可能持有的锁。若暂停线程调用了一个需要被暂停目标线程持有的锁的函数,就会导致死锁。
- 语法:
#include <thread.h> int thr_suspend(thread_t tid);- 返回值:
- 成功完成时返回零。
- 若
tid在当前进程中找不到,返回ESRCH。
以下是使用示例:
thread_t tid; /* tid from thr_create() */ pthread_t ptid; /* pthreads equivalent of Solaris tid from thread created with pthread_creat