Advanced Programming in the UNIX® Environment
ptg10805159 Section 11.4 Thread Creation 387 Figure11.2 creates one thread and prints the process and thread IDs of the new thre ...
ptg10805159 388 Threads Chapter 11 thread ID of the newly created thread through the first parameter (tidp). In our example, the ...
ptg10805159 Section 11.5 Thread Termination 389 Asingle thread can exit in three ways, thereby stopping its flow of control, wit ...
ptg10805159 390 Threads Chapter 11 printf("thread 2 exiting\n"); pthread_exit((void *)2); } int main(void) { int err; pthread_t ...
ptg10805159 Section 11.5 Thread Termination 391 Example The program in Figure11.4 shows the problem with using an automatic vari ...
ptg10805159 392 Threads Chapter 11 err = pthread_create(&tid2, NULL, thr_fn2, NULL); if (err != 0) err_exit(err, "can’t crea ...
ptg10805159 Section 11.5 Thread Termination 393 On Mac OS X, we get different results: $./a.out thread 1: structure at 0x1000b6f ...
ptg10805159 394 Threads Chapter 11 Athread can arrange for functions to be called when it exits, similar to the way that theatex ...
ptg10805159 Section 11.5 Thread Termination 395 { printf("thread 1 start\n"); pthread_cleanup_push(cleanup, "thread 1 first hand ...
ptg10805159 396 Threads Chapter 11 Running the program in Figure11.5 on Linux or Solaris gives us $./a.out thread 1 start thread ...
ptg10805159 Section 11.6 Thread Synchronization 397 #include <pthread.h> int pthread_detach(pthread_ttid); Returns: 0 if O ...
ptg10805159 398 Threads Chapter 11 read the variable, thread B acquires a lock. Similarly,when thread A updates the variable, it ...
ptg10805159 Section 11.6 Thread Synchronization 399 Thread A fetchiinto register (register = 5) increment the contents of the re ...
ptg10805159 400 Threads Chapter 11 see that the mutex is still locked and go back to waiting for it to become available again. I ...
ptg10805159 Section 11.6 Thread Synchronization 401 #include <stdlib.h> #include <pthread.h> struct foo { int f_coun ...
ptg10805159 402 Threads Chapter 11 necessary when we initialize the reference count to 1 in thefoo_allocfunction, because the al ...
ptg10805159 Section 11.6 Thread Synchronization 403 #include <stdlib.h> #include <pthread.h> #define NHASH 29 #defin ...
ptg10805159 404 Threads Chapter 11 struct foo *fp; pthread_mutex_lock(&hashlock); for (fp = fh[HASH(id)]; fp != NULL; fp = f ...
ptg10805159 Section 11.6 Thread Synchronization 405 Comparing Figure11.11with Figure11.10, we see that our allocation function n ...
ptg10805159 406 Threads Chapter 11 return(NULL); } idx = HASH(id); pthread_mutex_lock(&hashlock); fp->f_next = fh[idx]; f ...
«
17
18
19
20
21
22
23
24
25
26
»
Free download pdf