多核编程与并行计算实验报告 (1)(20)
发布时间:2021-06-07
发布时间:2021-06-07
多核编程与并行计算
实验十一:
// exa11.cpp : Defines the entry point for the console application. //
#include "stdafx.h"
#include <windows.h>
#include <conio.h>
#include <stdio.h>
#define THREAD_INSTANCE_NUMBER 3
LONG g_fResourceInUse = FALSE;
LONG g_lCounter = 0;
CRITICAL_SECTION cs;
DWORD ThreadProc1(void * pData) {
return 0; EnterCriticalSection(&cs); printf("ThreadProc1 %d enters into critical section\n",ThreadNumberTemp); Sleep(1000); LeaveCriticalSection(&cs); int ThreadNumberTemp = (*(int*) pData); printf("ThreadProc1: %d is running!\n",ThreadNumberTemp );