这是执行结果
先看实例代码:
#include "stdafx.h"
#include <Windows.h>
#include <string>
#include <set>
#include <io.h>
#include <fstream>
#include <Windows.h>
#include<time.h>
#include <stdio.h>
#include <process.h>
using namespace std;
CRITICAL_SECTION cs;
unsigned __stdcall thread1(LPVOID lpVoid)
{
clock_t t1,t2;
t1 = clock();
for ( int i = 0; i < 5000000; i++ )
{
EnterCriticalSection(&cs);
LeaveCriticalSection(&cs);
}
t2 = clock();
char buf[100]={0};
sprintf(buf, "thread1 t2-t1=%ld", t2-t1);
printf(buf);
printf("\n");
return 1;
}
unsigned __stdc