This preview shows page 1. Sign up to view the full content.
Unformatted text preview: anized in a rigid parent-child hierarchy. The threads associated with a process form a pool of peers, independent of which threads were created by which other threads. The main thread is distinguished from other threads only in the sense that it is always the ﬁrst thread to run in the process. The main impact of this notion of a pool of peers is that a thread can kill any of its peers, or wait for any of its peers to terminate. Further, each peer can read and write the same shared data. 566 CHAPTER 11. CONCURRENT PROGRAMMING WITH THREADS 11.2 Thread Control
Pthreads deﬁnes about 60 functions that allow C programs to create, kill, and reap threads, to share data safely with peer threads, and to notify peers about changes in the system state. However, most threaded programs use only a small subset of the functions deﬁned in the interface. Figure 11.5 shows a simple Pthreads program called hello.c. In this program, the main thread creates a peer thread and then waits for it to terminate. The peer thread prints “hello, world!\n” and terminates. When the main thread detects that the peer 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.
- Spring '10
- The American