linux 线程问题 - C/C++ / C语言
我用 pthread_create 创建一个线程,获得县城的id;
id是全局变量,我想中其他函数中消除这个函数,请问应该怎么做?
最好列出例子,谢谢。
没看明白啊....
void main()
{
pthread_t id;
_create(); //创建线程
_del(); //如何在这里把线程消灭?
}
_create()
{
pthread_create(&id,NULL...)
}
_del()
{
//????????????
}
int pthread_cancel (pthread_t thread);
Cancels the specified thread.
pthread_cancel 函数只是提出一个这样的请求,但不一定能终止线程,最好是在原来的线程里面搞个退出条件
while(_run){
}
//其他线程
//先不考虑同步问题
_run = 0;
In the default circumstances, pthread_cancel will cause the thread specified by tid to behave as if it had called pthread_exit with an argument of PTHREAD_CANCELED. However, a thread can elect to ignore or otherwise control how it is canceled. Note that pthread_cancel doesn 't wait for the thread to terminate. It merely makes &
相关问答:
写了个测试程序如下
struct hostent *hp;
char AlarmDevIP[20];
int x2;
hp = gethostbyname("www.google.com");
if (hp)
{
......
在根目录/lib中存放一个log.c,log.h,并用下面的语句:
gcc -c log.c
ar crv liblog.a log.o
编译出一个liblog.a静态库,然后在文件夹:/testfile中创建一个test.c和testc.c,test.c中引用了testc.c中定义的方法 ......
我的板子用嵌入式linux系统发送组播包给我PC虚拟机的linux,虚拟机的linux可以接收到,但是同样的程序,用虚拟机的linux发送,嵌入式linux却接收不到,具体表现为阻塞在recvfrom函数。
大致已经可以排除的问题:
1 ......
公司开发一个触摸屏程序,我负责的一块,实现这样一个功能,当鼠标点击窗口中图片(一张图分成几部分)的其中一部分时,将这部分图片截取出来,弹出新的窗口,将截取出的图片显示出来。我使用Rectange类控制了返回, ......
如何将一个ListBox中的数据存在数据库中的一个字段下面,并且每条记录的字符串个数不一定 以及如何从数据库中读取该ListBox中的所有记录
C/C++ code:
//存入数据库
void __fastcall TForm1::Button5Click(TO ......