zoukankan      html  css  js  c++  java
  • window多线程编程

    ======================================== 方法一=====================================================================================

    #include "stdafx.h"
    #include <stdio.h>
    #include <assert.h>
    #include <windows.h>
    #include <process.h>  // 包含这个头文件就行 

    ========================================方法二======================================================================================

    移植posix库:

    移植官网:

    ftp://sourceware.org/pub/pthreads-win32

    #include "stdafx.h"
    #include <stdio.h>
    #include <assert.h>
    #include <windows.h>
    #include <pthread.h>
    
    
    void* Function_t(void* Param);
    void* myFunction_t(void*MyParm);
    
    
    int main(int argc, _TCHAR* argv[])
    {
    	pthread_t pid;
    	pthread_attr_t attr;
    	pthread_attr_init(&attr);
    	pthread_attr_setscope(&attr, PTHREAD_SCOPE_PROCESS);
    	pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
    	pthread_create(&pid, &attr, Function_t, NULL);
    	pthread_create(&pid, &attr, myFunction_t, NULL);
    	printf("====
    ");
    	getchar();
    	pthread_attr_destroy(&attr);
    
    	CreateThread
    	return 0;
    }
    void* Function_t(void* Param)
    {
    	printf("Thread Starts.
    ");
    	pthread_t myid = pthread_self();
    
    	while (1)
    	{
    		printf("thread_one tid is %d
    ", myid.x);
    		fflush(stdout);
    		Sleep(1000);
    	}
    
    	return NULL;
    }
    
    void* myFunction_t(void*MyParm)
    {
    	printf("Thread Starts.
    ");
    	pthread_t myid = pthread_self();
    
    	while (1)
    	{
    		printf(" pthread my  pthread is  %d
    ", myid.x);
    		printf("my Function_t
    ");
    		Sleep(1000);
    
    	}
    
    	return NULL;
    }
    

      

    一勤天下无难事。
  • 相关阅读:
    【NOI1999、LOJ#10019】生日蛋糕(搜索、最优化剪枝、可行性剪枝)
    【NOI2016】区间
    【CodeForces688A】Opponents
    「LOJ10150」括号配对
    HDU6444(子段和、分情况比较)
    牛客练习赛41E(球的体积并)
    Codeforces 1154G(枚举)
    POJ1830(异或高斯消元)
    Codeforces 1114F(欧拉函数、线段树)
    牛客小白月赛13 G(双向搜索)
  • 原文地址:https://www.cnblogs.com/nowroot/p/12631711.html
Copyright © 2011-2022 走看看