Permalink
Browse files

Merge branch 'master' of github.com:jpvi/OperatingSystems

  • Loading branch information...
2 parents 8eaa130 + b5f7fd2 commit 7ff8e50a03a1c4f530b6ee0a306935e350cbb3e8 JP Villanueva committed Apr 5, 2012
Showing with 6 additions and 5 deletions.
  1. +6 −5 03a/lab3a_p2_win.c
View
@@ -9,14 +9,13 @@ void CreateThreadsWithSleep();
int global = 0;
CRITICAL_SECTION csl;
-HANDLE mReady;
int main() {
int i;
int param = 0;
DWORD *tid;
HANDLE *tid_handle;
-
+
InitializeCriticalSection(&csl);
tid = malloc(sizeof(DWORD) * 10);
@@ -44,20 +43,22 @@ int main() {
DWORD WINAPI AddToGlobal(LPVOID param) {
int local;
+ /* Start the critical section. */
EnterCriticalSection(&csl);
fprintf(stderr, "Hello, I'm thread %u.\n", (unsigned int)GetCurrentThreadId());
- Sleep(1000);
+ /* Sleep(1000); */
local = global;
fprintf(stderr, "Local: %d, TID: %u\n", local, (unsigned int)GetCurrentThreadId());
- Sleep(1000);
+ /* Sleep(1000); */
local += 10;
fprintf(stderr, "Local: %d, TID: %u\n", local, (unsigned int)GetCurrentThreadId());
global = local;
- Sleep(1000);
+ /* Sleep(1000); */
+ /* End the critical section. Remove this line to cause deadlock. */
LeaveCriticalSection(&csl);
return 0;

0 comments on commit 7ff8e50

Please sign in to comment.