2 an adapter plugged into an expansion slot on the io

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: hread_cond_wait(&cond, &mutex); Pthread_mutex_unlock(&mutex); } code/threads/barrier.c Figure 11.22: barrier.c: A simple barrier synchronization package. 590 #include <pthread.h> CHAPTER 11. CONCURRENT PROGRAMMING WITH THREADS int pthread cond timedwait(pthread cond t *cond, pthread mutex t *mutex, struct timespec *abstime); returns: 0 if OK, ETIMEDOUT if timeout The pthread cond timedwait function behaves like the pthread cond wait function, except that it returns with an error code of ETIMEDOUT once the value of the system clock exceeds the absolute time value in abstime. Figure 11.23 shows a handy routine that a thread can use to build the abstime argument each time it calls pthread cond timedwait: code/threads/maketimeout.c 1 2 3 4 5 6 7 8 9 10 11 #include "csapp.h" struct timespec *maketimeout(struct timespec *tp, int secs) { struct timeval now; gettimeofday(&now, NULL); tp->tv_sec = now.tv_sec + secs; tp->tv_nsec = now.tv_usec * 1000; return tp; } code/thr...
View Full Document

This note was uploaded on 09/02/2010 for the course ELECTRICAL 360 taught by Professor Schultz during the Spring '10 term at BYU.

Ask a homework question - tutors are online