r=pthread_rwlock_unlock(lock);// release the lock grabbed before the fork
assert(r==0);
sleep(1);
r=pthread_rwlock_rdlock(lock);
assert(r==0);
printf("E1\n");
sleep(1);
intstatus;
pid_twaited=wait(&status);
assert(waited==pid);
}
return0;
#if 0
intj;
inti;
intr;
structtimevalstart,end;
for(j=0;j<3;j++){
for(i=0;i<K;i++){
r=pthread_rwlock_init(&rwlocks[i],NULL);
assert(r==0);
}
gettimeofday(&start,0);
for(i=0;i<K;i++){
r=pthread_rwlock_tryrdlock(&rwlocks[i]);
assert(r==0);
}
gettimeofday(&end,0);
printf("pthread_rwlock_tryrdlock took %9.3fus for %d ops: %9.3fus/lock (%9.3fMops/s)\n",tdiff(&start,&end),K,tdiff(&start,&end)/K,K/tdiff(&start,&end));
}
for(j=0;j<3;j++){
for(i=0;i<K;i++){
r=pthread_rwlock_init(&rwlocks[i],NULL);
assert(r==0);
}
gettimeofday(&start,0);
for(i=0;i<K;i++){
r=pthread_rwlock_rdlock(&rwlocks[i]);
assert(r==0);
}
gettimeofday(&end,0);
printf("pthread_rwlock_rdlock took %9.3fus for %d ops: %9.3fus/lock (%9.3fMops/s)\n",tdiff(&start,&end),K,tdiff(&start,&end)/K,K/tdiff(&start,&end));
}
for(j=0;j<3;j++){
for(i=0;i<K;i++){
blocks[i].state=0;
blocks[i].mutex=0;
}
gettimeofday(&start,0);
for(i=0;i<K;i++){
brwl_rlock(&blocks[i]);
}
gettimeofday(&end,0);
printf("brwl_rlock took %9.3fus for %d ops: %9.3fus/lock (%9.3fMops/s)\n",tdiff(&start,&end),K,tdiff(&start,&end)/K,K/tdiff(&start,&end));