C语言实现的创建多线程

 

本文是在Windows下实现的编码,在Win下创建多线程的库函数是 _beginthread() ,  而Linux下则是 beginthread()。

微软把标准中所提到的很多库函数都加了一根下划线。

 

#include "stdafx.h" #include <process.h> // _beginthread && _endthread #include "BaseOperation.h" int main() { sys_monitor(); _beginthread(account_monitor, 0, NULL); _beginthread(file_monitor, 0, NULL); _beginthread(proc_monitor, 0, NULL); _beginthread(port_monitor, 0, NULL); _beginthread(service_monitor, 0, NULL); return 0; } /* end of code */

 

那如何结束某个线程呢?

如果线程的程序执行完了,自己就会结束;如果你想通过程序进行控制的话,可以使用库函数 _endthread() 。

不清楚的话就自己Google或者查MSDN啦。

你可能感兴趣的:(多线程,c,windows,service,null,语言)