如何保存ThreadOne的返回值,即0 [英] How do I save the return value of ThreadOne i.e. 0

查看:122
本文介绍了如何保存ThreadOne的返回值,即0的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

#include<stdio.h>
#include<windows.h>
#include<process.h>     // needed for _beginthread()


CRITICAL_SECTION m_cs;


int ThreadOne(void *Param){
	int i;
	//Lock the critical section
	EnterCriticalSection(&m_cs);
	for (i=0; i<10; i++){
		printf("Function 1 : %d\n", i);
	}
	//Release the Critical section
	LeaveCriticalSection(&m_cs);

	//Return the thread
	return 0;
}

int ThreadTwo(void *Param){
	int i;
	//Lock the critical section
	EnterCriticalSection(&m_cs);
	
	for (i=0; i<10; i++){
		printf("Function 2 : %d\n", i);
	}
	//Release the Critical section
	LeaveCriticalSection(&m_cs);

	//Return the thread
	return 0;
}

int main()
{    
	// Create the array of Handle
	HANDLE hThrd[2];
	
	//Initialize the critical section
	InitializeCriticalSection(&m_cs);
	
	// Create threads use CreateThread function with NULL Security
	hThrd[0] = _beginthread(ThreadOne, 0, (void *)0);
	hThrd[1] = _beginthread(ThreadTwo, 0, (void *)0);
		
	// Wait for the main thread 
	WaitForMultipleObjects(2,hThrd,TRUE,INFINITE);

	// Delete critical Section
	DeleteCriticalSection(&m_cs);

	getchar();
	return 0;
}

推荐答案

您可以使用检索线程返回值https://msdn.microsoft.com/it-it/library/windows/desktop/ms683190(v=vs.85).aspx\">GetExitCodeThread [ ^ ] function。
You may retrieve the thread return value using the GetExitCodeThread[^] function.


这篇关于如何保存ThreadOne的返回值,即0的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆