We will not discuss its inner workings and we will

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: = *sp; /* copy the shared struct to the unshared one */ Pthread_mutex_unlock(&mutex); return up; } code/threads/maketimeout t.c Figure 11.27: maketimeout t: A version of maketimeout that is thread-safe but not reentrant. code/threads/maketimeout r.c 1 2 3 4 5 6 7 8 9 10 11 #include "csapp.h" struct timespec *maketimeout_r(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/threads/maketimeout r.c Figure 11.28: maketimeout r: A version of maketimeout that is reentrant and thread-safe. 596 CHAPTER 11. CONCURRENT PROGRAMMING WITH THREADS 11.6.2 Thread-safe Library Functions Most Unix functions and the functions defined in the standard C library (such as malloc, free, realloc, printf, and scanf) are thread-safe, with only a few exceptions. Figure 11.29 lists the common exceptions. (See [77] for a complete list.) Thread-unsafe function asctime ctime gethostbyaddr gethostbyname inet ntoa localtime rand Thread-unsafe class 3 3 3 3 3 3 2 U...
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