Skip to content

Commit 09b6081

Browse files
committed
perform number of iterations in each reader thread
it demonstrates the functionality better
1 parent 5335f6e commit 09b6081

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

pthreads/pthread-rwlock.c

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ pthread_rwlock_t rwlock = PTHREAD_RWLOCK_INITIALIZER;
2828

2929
void *properties[MAX_PROPS];
3030

31+
#define MAX_ITER 100
32+
3133
static void
3234
millisleep(int msec)
3335
{
@@ -89,9 +91,11 @@ writer_thread(void *arg)
8991
static void *
9092
reader_thread(void *arg)
9193
{
92-
int rnd = random() % MAX_PROPS;
93-
void *val = prop_get(rnd);
94-
printf("got %p for %d\n", val, rnd);
94+
for (int i = 0; i < MAX_ITER; i++) {
95+
int rnd = random() % MAX_PROPS;
96+
void *val = prop_get(rnd);
97+
printf("got %p for %d\n", val, rnd);
98+
}
9599
return (NULL);
96100
}
97101

0 commit comments

Comments
 (0)