c++ 网页线程提交
将主函数调整如下,就解决问题了:
void main()
{
HANDLE hThread1, hThread2;
hMutex = CreateMutex(NULL, FALSE, NULL);
ReleaseMutex(hMutex);
hThread1 = ::CreateThread(NULL, 0, Fun1Proc, NULL, 0, NULL);
hThread2 = ::CreateThread(NULL, 0, Fun2Proc, NULL, 0, NULL);
CloseHandle(hThread1);
CloseHandle(hThread2);
Sleep(1000);
}
知道为什么了吧?呵呵
c++使用线程的简单代码
创建5个线程
#include
#include
void* work_thread(void* arg)
{
//线程执行体
return 0;
}
int main(int argc,char* argv[])
{
int nthread = 5;//创建线程的个数
pthread_t tid;//声明一个线程ID的变量;
for(int i=0;i<nthread;i++)
{
pthread_create(&tid,NULL,work_thread,NULL);
}
sleep(60);//睡眠一分钟,你可以看下线程的运行情况,不然主进程会很快节结束了。
}
pthread_create(&tid,NULL,work_thread,NULL);//创建线程的函数,第一个参数返回线程的ID;第二个参数是线程的属性,一般都置为NULL;第三个参数是线程函数,线程在启动以后,会自动执行这个函数;第四个参数是线程函数的参数,如果有需要传递给线程函数的参数,可以放在这个位置,可以是基础类型,如果你有不止一个参数想传进线程函数,可以做一个结构体,然后传入。
如果线程处理的问题不同可以一个一个创建线程,当然线程函数也要一个一个写了。

