pthread_detach pthread_create实例
//pool.h
1 #ifndef POOL_H
#define POOL_H
#include <pthread.h> class pool
{
public:
pool();
~pool(); void func();
static void *schedule(void *ptr);
int schedule_thread();
/*
private:
pthread_t pid;
void *params;
*/
}; #endif // POOL_H
//pool.cpp
1 #include <iostream>
#include <stdio.h>
#include <pthread.h>
#include "pool.h"
using namespace std;
pool::pool()
{
cout << "pool()" << endl;
} pool::~pool()
{
cout << "~pool()" << endl;
} void pool::func(){
cout << "pool::func" << endl;
} //void *pool::schedule(void *ptr){
void *pool::schedule(void *ptr){
cout << "enter pool::schedule" << endl;
//unjoinable属性可以在pthread_create时指定,或在线程创建后在线程中pthread_detach自己,
int res = pthread_detach(pthread_self());
if(res != ){
printf("please check /proc/%ld/maps\n", pthread_self());
}
pool *p = (pool *)ptr;
p->func();
cout << "leave schedule" << endl;
return ;
} int pool::schedule_thread(){
cout << "enter pool::schedule_thread" << endl;
pthread_t pid;
//if(pthread_create(&pid , NULL ,schedule, (void *)this) != 0){
if(pthread_create(&pid , NULL ,schedule, (void *)this) != ){
cerr << "schedule thread create fail" << endl;
return -;
}
cout << "leave pool::schedule_thread" << endl;
return ;
}
//main.cpp
#include<stdio.h>
#include <stdlib.h>
#include <string.h>
#include "pool.h"
int main(void)
{
pool *pl = new pool();
// pl.func();
pool::schedule(pl);
//pl.schedule_thread();
delete pl;
return ;
}
pthread_detach pthread_create实例的更多相关文章
- linux线程(二)内存释放
linux线程有两种模式joinable和unjoinable. joinable线程:系统会保存线程资源(栈.ID.退出状态等)直到线程退出并且被其他线程join. unjoinable线程:系统会 ...
- linux服务器开发二(系统编程)--线程相关
线程概念 什么是线程 LWP:Light Weight Process,轻量级的进程,本质仍是进程(在Linux环境下). 进程:独立地址空间,拥有PCB. 线程:也有PCB,但没有独立的地址空间(共 ...
- linux系统编程--线程
安装线程man page,命令:sudo apt-get install manpages-posix-dev 线程概念 什么是线程 LWP:light weight process 轻量级的进程,本 ...
- 最近学习工作流 推荐一个activiti 的教程文档
全文地址:http://www.mossle.com/docs/activiti/ Activiti 5.15 用户手册 Table of Contents 1. 简介 协议 下载 源码 必要的软件 ...
- Linux多线程实例练习 - pthread_create()
Linux多线程实例练习 pthread_create():创建一个线程 int pthread_create(pthread_t *tidp, const pthread_attr_t *attr, ...
- pthread_detach pthread_join pthread_create
pthread_create:创建线程以后线程直接开始运行: pthread_detach pthread_join:线程资源的释放方式. 创建一个线程默认的状态是joinable, 如果一个线程结束 ...
- 静态成员函数与pthread_create,纯虚函数匹配使用实例
最近在浏览朋友写的代码,发现有一个细节非常值得学习,在这里将代码贴出来简单分享一下: #ifndef THREAD_H_ #define THREAD_H_ #include <pthread. ...
- pthread_create线程创建的过程剖析(转)
概述 在Linux环境下,pthread库提供的pthread_create()API函数,用于创建一个线程.线程创建失败时,它可能会返回ENOMEM或EAGAIN.这篇文章主要讨论线程创建过程中碰到 ...
- linux 读写锁应用实例
转自:http://blog.csdn.net/dsg333/article/details/22113489 /*使用读写锁实现四个线程读写一段程序的实例,共创建了四个新的线程,其中两个线程用来读取 ...
随机推荐
- MiZ702学习笔记10——文本实例化IP的方法
之前,添加vivado自带IP的时候,都是以图形化的方式:一般是新建一个Block Design顶层文件,然后将图形化的ip贴到,Block Design中. 但是,在进行PL的开发过程中,有时不想使 ...
- 《Effective Java》学习笔记 ——异常
充分发挥异常的优点,可以提高程序的可读性.可靠性和可维护性. 第57条 只针对异常的情况才使用异常 第58条 对可恢复的情况使用受检异常,对编程错误使用运行时异常 * 如果期望调用者能够适当的恢复,使 ...
- 《HTTP权威指南》读书笔记:缓存
缓存的定义 Web缓存是可以自动保存常见文档副本的HTTP设备(包括浏览器?) 缓存的作用 减少冗余数据传输 缓解带宽瓶颈(很多网络为本地网络客户端提供的带宽比为远程服务器提供的带宽要宽) 缓解瞬时拥 ...
- jupyter notebook 更改工作环境和浏览器
转载自:https://blog.csdn.net/u011141114/article/details/78556227 1 修改默认目录 最近刚刚开始学习Python,比较好的一个IDE就是jup ...
- imagick用法!
https://coderwall.com/p/9hj97w sudo apt-get install imagemagick sudo apt-get install php5-imagick su ...
- CSS——【元素内边距padding、元素外边距margin、元素边框border-width、元素大小width/height】与【元素显示大小】的关系
一.基本知识 padding:元素内边距,指的是元素内边框到元素中内容的距离. 用法: padding:长度|百分比 padding-top:长度|百分比 padding-bottom:长度|百分比 ...
- Leetcode——30.与所有单词相关联的字串【##】
@author: ZZQ @software: PyCharm @file: leetcode30_findSubstring.py @time: 2018/11/20 19:14 题目要求: 给定一 ...
- ElasticSearch 2 (15) - 深入搜索系列之多字段搜索
ElasticSearch 2 (15) - 深入搜索系列之多字段搜索 摘要 查询很少是简单的一句话匹配(one-clause match)查询.很多时候,我们需要用相同或不同的字符串查询1个或多个字 ...
- Beta博客集合
Beta博客集合 Task1:beta冲刺准备 冲刺准备 Task2:Beta阶段冲刺合集 Beta阶段冲刺一 Beta阶段冲刺二 Beta阶段冲刺三 Beta阶段冲刺四 Beta阶段冲刺五 Task ...
- Beta冲刺——day5
Beta冲刺--day5 作业链接 Beta冲刺随笔集 github地址 团队成员 031602636 许舒玲(队长) 031602237 吴杰婷 031602220 雷博浩 031602134 王龙 ...
