C++多线程 文件的异步读写

#include 
#include 
#include 
#include
using namespace std;
DWORD WINAPI MyThreadProc1(LPVOID lpParameter);
DWORD WINAPI MyThreadProc2(LPVOID lpParameter);
const char * filename = "C:\\Users\\rohon\\Desktop\\example.txt";
int array[100000];
int i = 0;
int j = 0;
int flag = 0;
CRITICAL_SECTION g_cs;
HANDLE hMutex;
void ThreadMethod()
{
	memset(array,0,sizeof(array));
	InitializeCriticalSection(&g_cs);
	i = 0;
	j = 0;
	HANDLE handle1,handle2;
	handle1 = CreateThread(NULL,0,MyThreadProc1,NULL,0,NULL);
	handle2 = CreateThread(NULL,0,MyThreadProc2,NULL,0,NULL);
	WaitForSingleObject(handle2,INFINITE);
	CloseHandle(handle1);
	CloseHandle(handle2);
}
//void WHfun()
//{
//	cout<<"World Hello!"<

thread1写操作,thread2读操作,异步进行,输出的只有thread2从文件里边读到的数据。

你可能感兴趣的:(C++)