码迷,mamicode.com
首页 >  
搜索关键字:pthread    ( 1177个结果
多线程笔试题(linux)
子线程循环10次,接着主线程循环100次,接着又回到子线程循环10次,接着再回到主线程又循环100次,如此循环50次,试写出代码。#include #include #include #include pthread_attr_t attr;pthread_mutex_t mutex;pthre.....
分类:编程语言   时间:2014-09-23 02:26:13    阅读次数:265
pthread_attr_init线程属性
1.线程属性线程具有属性,用pthread_attr_t表示,在对该结构进行处理之前必须进行初始化,在使用后需要对其去除初始化。我们用pthread_attr_init函数对其初始化,用pthread_attr_destroy对其去除初始化。1.名称::pthread_attr_init/pthre...
分类:编程语言   时间:2014-09-23 01:19:23    阅读次数:323
《UNIX环境高级编程》读书笔记之进程环境
1.进程终止 有八种方式使进程终止 (1)从main返回 (2)调用exit; (3)调用_exit或者_Exit; (4)最后一个线程从其启动历程返回 (5)最后一个线程调用pthread_exit; 异常终止方式有三种: (6)调用abort(); (7)接到一个信号; (8)最后一个线程对取消请求做出相应 三个函数用于正常终止一个程序: #include ...
分类:其他好文   时间:2014-09-19 17:40:45    阅读次数:208
pthread_once和pthread_key_create的用法演示
static pthread_key_t key;static pthread_once_t key_once = PTHREAD_ONCE_INIT;void make_key(){ fprintf(stderr, "make_key\n"); pthread_key_create(&...
分类:其他好文   时间:2014-09-18 22:07:44    阅读次数:454
线程的条件变量实例
情景1:Jack开着一辆出租车来到一个站点停车,看见没人就走了。过段时间,Susan来到站点准备乘车,但是没有来,于是就等着。过了一会Mike开着车来到了这个站点,Sunsan就上了Mike的车走了。如图所示:程序实现该情景:#include #include #include #include pthread_cond_t taxicond = PTHREAD_COND_INITIAL...
分类:编程语言   时间:2014-09-17 15:14:32    阅读次数:288
pthread编译时报错的解决方法
最近在学习POSIX thread编程,今天编译一个程序报如下错误:/tmp/ccXH8mJy.o:在函数‘main’中:deadlock.c:(.text+0xbb):对‘pthread_create’未定义的引用deadlock.c:(.text+0x134):对‘pthread_join’未定...
分类:其他好文   时间:2014-09-15 00:52:47    阅读次数:237
成员函数作为线程函数调用
遇到的问题          我们在编程中需要把数据封装成一个类,调用pthread_create 利用成员函数去创建一个线程往往是不成功的! error: argumentof type ‘void* (Threadpool::)(void*)’ does not match ‘void* (*)(void*)’ 出现类型不匹配的问题。因为pthread_create需要的参数类型为voi...
分类:编程语言   时间:2014-09-14 18:07:37    阅读次数:243
Linux下c++11多线程聊天室
刚看的c++11多线程,写个聊天室试试编译的时候加上c++11和多线程库g++-Wall-std=c++0x-pthread-oserverserver.cppserver和client都是q退出?1. [代码]server.cpp #include #include #include #incl....
分类:编程语言   时间:2014-09-13 17:05:35    阅读次数:229
pthread——pthread_cleanup
Pthread_cleanup用于注册线程清理函数,注册的清理函数将在线程被取消或者主动调用pthread_exit时被调用; 一个简单的示例: #include #include // pthread_cleanup_push and pthread_cleanup_pop should be c...
分类:其他好文   时间:2014-09-10 23:47:31    阅读次数:249
linux应用编程之线程编程
1 线程创建 #include #include #include void thread(void) { int i; for(i=0;i<3;i++) { printf("this is a pthread\n"); } } int main(void) { pthread_t id; int i,ret; ret = pthread_create(&id,N...
分类:编程语言   时间:2014-09-10 17:49:00    阅读次数:276
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!