多线程编程

来源:互联网 发布:c 软件开发视频教程 编辑:程序博客网 时间:2024/06/05 16:30
#include <pthread.h>int pthread_create(pthread_t *tid, const pthread_attr_t *attr, void *(*fun)(void *), void *arg);/* * 创建线程 * @tid —— 线程id的类型为pthread_t,成功创建后的线程由tid返回。 * @attr —— 指定创建线程的属性,如线程优先级、初试栈大小、是否为守护进程。一般使用NULL来指定默认值。 * @func —— 通过func来指定创建线程后,所有执行的函数。 * @arg —— 线程执行函数的参数 * return —— 创建成功返回0. */int pthread_join(pthread_t *tid, void **status);/* * 等待线程tid退出 * @tid —— 指定要等待的线程ID * @status —— 如果不为NULL,那么线程的返回值存储在status指向的空间中 * return —— 执行成功返回0 */void pthread_exit(void *status)/* * 终止线程 * @status —— 指定线程终止的返回值 */pthread_t pthread_self(void)/* * 获取当前线程的ID */int pthread_equal(pthread_t tid1, pthread_t tid2);/* * 比较两个线程ID  * 相等返回非0值, 不等返回0 */int pthread_cancel(pthead_t tid);/* * 取消统一进程中的其他线程 * 成功返回0, 失败返回错误编号 */int pthread_detach(pthrad_t tid);/* * 指定线程变为分离状态 * 分离状态的线程退出,将释放多有的资源,不是分离状态的线程退出后就变成了僵死线程 */

原创粉丝点击