ChinaUnix.net
相关文章推荐:

线程之外的函数中使用pthread函数

要退出线程用哪个好呢? 我以前同事写了一个程序,退出线程pthread_cancel(ThreadId, SIGKILL); 开始编译通过,运行的时候也没任何问题,我现在换了arm gcc编译器,编译说:'SIGKILL' undeclared 后来查了资料,才知道它们两个的原型:pthread_cancel(ThreadId); pthread_kill(ThreadId, SIGKILL); 那退出线程用哪个呢? 以前同事写的pthread_cancel(ThreadId, SIGKILL)为什么...

by herocsz - C/C++ - 2009-08-05 18:14:35 阅读(3156) 回复(1)

相关讨论

关于线程函数的问题? #include #include #include #include #include #include #include #include <pthread.h> #include #define BACKLOG 5//允许连接的客户的最大个数 #define PORT 1234//开放的端口 #define MAXDATASIZE 1000// void process_cli(int connectfd,struct sockaddr_in client); //利用连接套接字connectf...

by DNS_WXC - C/C++ - 2008-01-10 17:59:41 阅读(3360) 回复(4)

在SOLARIS C++4。2下在一个类的成员里调用了一个线程, int myClass::start() { ................ thr_id = pthread_create(&thread_id, NULL, thread_method, NULL); ........................ } 但必须把thread_method声明如下: void *thread_method(void *arg) 如果声明为void * myclass::thread_method(void *arg) 就编译不过,我想把它作为成员函数,怎么办???不然破坏封装性

by libad - C/C++ - 2003-10-15 09:16:50 阅读(4256) 回复(13)

线程pthread_create就是随时都在工作的一个函数 这样理解对不对?

by mousexqshe - C/C++ - 2007-07-09 13:06:08 阅读(1590) 回复(6)

今天发现win2000 + vmware + redhat9下, pthread_setcancelstate(pthread_CANCEL_DISABLE,&nOldType); 没有起作用,也就是说就算设置了pthread_CANCEL_DISABLE,也会被pthread_cancel 函数cancel掉 测试程序如下 [code] #include #include #include #include #include <pthread.h> pthread_t pid1; void func_1(void) { int i ; int nOldType; int nRet = pthread_setcancelstat...

by fzy8888cn - 虚拟化与云服务 - 2006-07-24 16:06:15 阅读(2583) 回复(11)

[code] #include #include #include <pthread.h> #include void *print_message_function( void *ptr ); int main() { pthread_t thread1, thread2; char *message1 = "Hello"; char *message2 = "World"; printf("aaaaaaaaaa11\n"); pthread_create(&thread1, NULL,print_message_function, (void *)message1); pthread_join(thread1, NULL); ...

by openX - C/C++ - 2005-12-15 14:44:00 阅读(2835) 回复(5)

[code] #include ; #include ; #include ; #include <pthread.h>; int main( void ) { int rc = -1; for( int i=1; i<5; i++ ) { rc = pthread_cancel(i); if(rc == 0) { printf( "kill thread %d OK\n", i ); } else { printf( "kill thread %d error : %d\n", i, rc ); } } return 0; } // 输出结果如下 $ CC thread.c -lpthread -o thread1 $ CC thread.c -o thr...

by feeling - C/C++ - 2004-11-05 17:15:42 阅读(1454) 回复(0)

pthread_create (&tid, NULL, mythread, NULL); 如果 mythread是Myclass的成员函数, void* Myclass::mythread(void *) 就会出现( void*)(*)不能overloaded等错误 如果就是普通的函数, 不是类里面的, 就没关西 大侠们说, 该怎么用类里面的函数线程?

by made_in_chn - C/C++ - 2004-08-15 20:22:27 阅读(936) 回复(3)

pthread_create (&tid, NULL, mythread, NULL); 如果 mythread是Myclass的成员函数, void* Myclass::mythread(void *) 就会出现( void*)(*)不能overloaded等错误 如果就是普通的函数, 不是类里面的, 就没关西 大侠们说, 该怎么用类里面的函数线程?

by made_in_chn - 内核/嵌入技术 - 2004-08-15 20:29:34 阅读(786) 回复(3)

我在A线程中调用pthread_cancel函数来终止B线程,它们不是同一类线程,但在同一个进程中。终止没有达到要求的效果? 运行环境为HP UNix ,B线程没有设置取消属性,用系统默认值。 程序运行时用glance可以观察到,调用pthread_cancel函数前,程序有60个线程,希望调用10次pthread_cancel函数终止10个线程(每次终止不同的线程号),每次调用返回均为0,但是调用后由glance观测到程序还有59个线程,只终止了一个? 为什么那? 请大...

by newman_xpb - 程序开发 - 2003-10-17 13:41:37 阅读(939) 回复(1)

在一个线程函数里面直接return NULL和用pthread_exit(0)有什么不同? void * thread(void *arg) { 直接return NULL和用pthread_exit(0)有什么不同? }

by libad - C/C++ - 2004-12-22 20:13:37 阅读(1773) 回复(1)