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;
    }
    

      

    一勤天下无难事。
  • 相关阅读:
    go时间和日期转换
    go操作mysql
    Python常见错误处理
    C++ 常见问题
    CF605E Intergalaxy Trips
    均分纸牌详解
    P4447 [AHOI2018初中组]分组
    P4537 [CQOI2007]矩形
    P4823 [TJOI2013]拯救小矮人
    P5132 Cozy Glow之拯救小马国
  • 原文地址:https://www.cnblogs.com/nowroot/p/12631711.html
Copyright © 2011-2022 走看看