4---能正常运行的多线程最简单模型

#include <stdio.h>  
#include <windows.h>  
char buffer[100] = { 'x' , 'y' , 'z' }; 
int W_A=0,R_A=0;
//子线程函数 1 
DWORD WINAPI ThreadFun1(LPVOID pM) 
  { 
   while (1)
   {
    //printf("子线程的线程1    ");
    // R_buffer[]={0,1,2,3,4,5,6,7,8,9};
   // buffer
   }
   return 0;
  } 
//子线程函数 2
 
DWORD WINAPI ThreadFun2(LPVOID pM) 
 { 
  FILE *fp;
  fp = fopen ( "myfile.txt" , "wb" );
  // fseek(fp,100,0);
  while (1)
    { 
     //printf("子线程的线程2");
     fwrite (buffer , sizeof(buffer), 1 , fp );
    }

  fclose (fp);
  return 0; 
 } 

//主函数,所谓主函数其实就是主线程执行的函数。  
int main() 

  HANDLE handle1;
  HANDLE handle2;
 
     printf("     最简单的创建多线程实例\n"); 
     handle1= CreateThread(NULL, 0, ThreadFun1, NULL, 0, NULL); 
     handle2= CreateThread(NULL, 0, ThreadFun2, NULL, 0, NULL); 

  while (1);//一直运行线程
  return 0; 
}

你可能感兴趣的:(多线程)