在Windows上使用线程.简单的例子?

前端之家收集整理的这篇文章主要介绍了在Windows上使用线程.简单的例子?前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我需要什么,如何在 Windows Vista上使用C中的线程?

你能给我一个简单的代码示例吗?

这是 MSDN sample关于如何在Windows上使用CreateThread().

基本思想是您调用CreateThread()并传递一个指向你的线程函数的指针,这是在目标线程创建后将会运行的.

最简单的代码是:

@H_404_11@#include <windows.h> DWORD WINAPI ThreadFunc(void* data) { // Do stuff. This will be the first function called on the new thread. // When this function returns,the thread goes away. See MSDN for more details. return 0; } int main() { HANDLE thread = CreateThread(NULL,ThreadFunc,NULL,NULL); if (thread) { // Optionally do stuff,such as wait on the thread. } }

您也可以选择调用SHCreateThread()相同的基本思想,但是如果您要求它(如初始化COM)等会为您执行一些shell类型的初始化.

猜你在找的Windows相关文章