8 hardware and software organization of an internet

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: CONCURRENT PROGRAMMING WITH THREADS All functions thread-safe functions reentrant functions non-thread-safe functions Figure 11.25: Relationships between the sets of reentrant, thread-safe, and non-thread-safe functions. non-shared data. In the rest of the book, we will use the term reentrant to include both explicit and implicit reentrant functions, but it is important to realize that reentrancy is sometimes a property of both the caller and the callee. To understand the distinctions between thread-unsafe, thread-safe, and reentrant functions more clearly, let’s consider different versions of our maketimeout function from Figure 11.23. We will start with the function in Figure 11.26, a thread-unsafe function that returns a pointer to a static variable. code/threads/maketimeout u.c 1 2 3 4 5 6 7 8 9 10 11 12 #include "csapp.h" struct timespec *maketimeout_u(int secs) { static struct timespec timespec; struct timeval now; gettimeofday(&now, NULL); timespec.tv_sec = now.tv_sec + secs; times...
View Full Document

Ask a homework question - tutors are online