source: CIVL/examples/pthread/errorTest/rwlockExample.c@ a389857

main test-branch
Last change on this file since a389857 was ea777aa, checked in by Alex Wilton <awilton@…>, 3 years ago

Moved examples, include, build_default.properties, common.xml, and README out from dev.civl.com into the root of the repo.

git-svn-id: svn://vsl.cis.udel.edu/civl/trunk@5704 fb995dde-84ed-4084-dfe6-e5aef3e2452c

  • Property mode set to 100644
File size: 613 bytes
Line 
1#include <pthread.h>
2
3#define SIZE 3
4
5pthread_rwlock_t lock;
6int glob = 0;
7int y = 0;
8int * yptr = &y;
9
10void * reader(void * arg){
11 pthread_rwlock_rdlock(&lock);
12 *yptr = glob;
13 pthread_rwlock_unlock(&lock);
14}
15
16void * writer(void * arg){
17 pthread_rwlock_wrlock(&lock);
18 glob++;
19 pthread_rwlock_unlock(&lock);
20}
21
22
23int main(){
24 pthread_t threads[SIZE];
25 pthread_rwlock_init(&lock, NULL);
26 for(int x = 0; x < SIZE; x++){
27 if(x % 3 == 0){
28 pthread_create(&threads[x], NULL, writer, NULL);
29 }
30 else{
31 pthread_create(&threads[x], NULL, reader, NULL);
32 }
33 }
34 pthread_exit(NULL);
35}
Note: See TracBrowser for help on using the repository browser.