The Linux Programming Interface
Chapter 29: Threads: Introduction In this and the next few chapters, we describe POSIX threads, often known as Pthreads. We won’ ...
618 Chapter 29 We have simplified things somewhat in Figure 29-1. In particular, the location of the per-thread stacks may be in ...
Threads: Introduction 619 makes it possible to serve multiple clients simultaneously. While this approach works well for many sc ...
620 Chapter 29 Among the attributes that are distinct for each thread are the following: z thread ID (Section 29.5); z signal ma ...
Threads: Introduction 621 SUSv3 doesn’t specify how these data types should be represented, and portable programs should treat t ...
622 Chapter 29 Compiling Pthreads programs On Linux, programs that use the Pthreads API must be compiled with the cc –pthread op ...
Threads: Introduction 623 wrongly appear that the thread was canceled. In an application that employs thread cancellation and ch ...
624 Chapter 29 Calling pthread_exit() is equivalent to performing a return in the thread’s start func- tion, with the difference ...
Threads: Introduction 625 The pthread_equal() function is needed because the pthread_t data type must be treated as opaque data. ...
626 Chapter 29 If a thread is not detached (see Section 29.7), then we must join with it using pthread_join(). If we fail to do ...
Threads: Introduction 627 int main(int argc, char *argv[]) { pthread_t t1; void *res; int s; s = pthread_create(&t1, NULL, t ...
628 Chapter 29 Once a thread has been detached, it is no longer possible to use pthread_join() to obtain its return status, and ...
Threads: Introduction 629 29.9 Threads Versus Processes In this section, we briefly consider some of the factors that might infl ...
630 Chapter 29 number of other attributes, including process ID, open file descriptors, signal dis- positions, current working d ...
THREADS: THREAD SYNCHRONIZATION In this chapter, we describe two tools that threads can use to synchronize their actions: mutexe ...
632 Chapter 30 loc, incrementing loc, and copying loc back to glob. (Since loc is an automatic variable allocated on the per-thr ...
Threads: Thread Synchronization 633 Figure 30-1: Two threads incrementing a global variable without synchronization When we run ...
634 Chapter 30 Thread 1 receives another time slice and resumes execution where it left off. Having previously (step 1) copied ...
Threads: Thread Synchronization 635 If multiple threads try to execute this block of code (a critical section), the fact that on ...
636 Chapter 30 To lock a mutex, we specify the mutex in a call to pthread_mutex_lock(). If the mutex is currently unlocked, this ...
«
29
30
31
32
33
34
35
36
37
38
»
Free download pdf