[ create a new paste ] login | about

Link: http://codepad.org/uT4vqEj9    [ raw code | fork ]

C, pasted on Feb 1:
#include <windows.h>
#include <stdio.h>

int g = 0;

DWORD WINAPI Thread1(LPVOID param) {
	int i;
	for (i = 0; i < 10000000; i++) {
		g += 2;
	}
	return 0;
}

DWORD WINAPI Thread2(LPVOID param) {
	int i;
	for (i = 0; i < 10000000; i++) {
		g += 3;
	}
	return 0;
}

int main()
{
	HANDLE handle1, handle2;
	handle1 = CreateThread(NULL, 0, &Thread1, NULL, CREATE_SUSPENDED, NULL);
	handle2 = CreateThread(NULL, 0, &Thread2, NULL, CREATE_SUSPENDED, NULL);
	ResumeThread(handle1);
	ResumeThread(handle2);
	WaitForSingleObject(handle1, INFINITE);
	WaitForSingleObject(handle2, INFINITE);
	CloseHandle(handle1);
	CloseHandle(handle2);
	printf("%d\n", g);
	return 0;
}


Create a new paste based on this one


Comments: