Windows Visual C++多线程(Thread)编程示例

    以前总以为用C来编写多线程序是一件很难的事, 但事实上并不是很复杂, 下面就是今天参考网上例子写出来的一段程序.

#include <process.h>
#include <stdio.h>
#include <stdlib.h>

void Child( void* pParams )
{
   char *data = (char *) pParams;
   printf("Child first (%s) !\n", data);
   _endthread();
}
  
int main( void )
{
   char data[] = "1234567890";
   _beginthread( Child, 0, (void *)data);
   _sleep(10);
   printf("Parent later!\n");
   return 0;
}

    用"cl /MT"命令编译后, 运行的结果如下:

C:\TEMP>test
Child first (1234567890) !
Parent later!

    研究多线程的原因是想并行执行几个SQL语句, 及定时发出SQL查询请求.

发表留言:

« Previous | Main | Next »

英语900句 | English 900

  • What's the capital of your country?
  • 贵国首都是哪儿?
  • I come from Japan.
  • 我来自日本.
  • I was born in China and brought up in the U.S.A.
  • 我出生在中国, 在美国长大.
  • My country has an area of 500,000 square kilometers.
  • 我国面积五十万平里.
  • The capital of my country id Beijing.
  • 我国首都是北京.