-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
added some notes on locks, deadlocks and races
- Loading branch information
1 parent
d60b925
commit 10db98e
Showing
6 changed files
with
141 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,4 +8,6 @@ | |
/*.toc | ||
/*.fdb_latexmk | ||
/*.fls | ||
/*.sty | ||
/*.loe | ||
/_region_.tex |
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
#include <pthread.h> | ||
#include <stdio.h> | ||
#include <omp.h> | ||
|
||
int main(int argc, char* argv[]) { | ||
|
||
int count = 0; | ||
int total = 1000000; | ||
pthread_mutex_t lock; | ||
|
||
pthread_mutex_init(&lock, NULL); | ||
|
||
#pragma omp parallel for | ||
for (int i=0; i<total; i++) | ||
{ | ||
pthread_mutex_lock(&lock); | ||
count++; | ||
pthread_mutex_unlock(&lock); | ||
} | ||
|
||
printf("Final count is: %d\n", count); | ||
printf("Should be: %d\n", total); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
#include <stdio.h> | ||
#include <omp.h> | ||
|
||
int main(int argc, char* argv[]) { | ||
|
||
int count = 0; | ||
int total = 1000000; | ||
#pragma omp parallel for | ||
for (int i=0; i<total; i++) | ||
{ | ||
count++; | ||
} | ||
printf("Final count is: %d\n", count); | ||
printf("Should be: %d\n", total); | ||
} |