TAILIEUCHUNG - Parallel Programming: for Multicore and Cluster Systems- P31

Parallel Programming: for Multicore and Cluster Systems- P31: Innovations in hardware architecture, like hyper-threading or multicore processors, mean that parallel computing resources are available for inexpensive desktop computers. In only a few years, many standard software products will be based on concepts of parallel programming implemented on such hardware, and the range of applications will be much broader than that of scientific computing, up to now the main application area for parallel computing | 292 6 Thread Programming int pthread_attr_init pthread_attr_t attr . This leads to an initialization with the default attributes corresponding to the default characteristics. By changing an attribute value the characteristics can be changed. Pthreads provide attributes to influence the return value of threads setting the size and address of the runtime stack or the cancellation behavior of the thread. For each attribute Pthreads define functions to get and set the current attribute value. But Pthreads implementations are not required to support the modification of all attributes. In the following the most important aspects are described. Return Value An important property of a thread is its behavior concerning thread termination. This is captured by the attribute detachstate. This attribute can be influenced by all Pthreads libraries. By default the runtime system assumes that the return value of a thread T1 may be used by another thread after the termination of T1. Therefore the internal data structure maintained for a thread will be kept by the runtime system after the termination of a thread until another thread retrieves the return value using pthread_join see Sect. . Thus a thread may bind resources even after its termination. This can be avoided if the programmer knows in advance that the return value of a thread will not be needed. If so the thread can be generated such that its resources are immediately returned to the runtime system after its termination. This can be achieved by changing the detachstate attribute. The following two functions are provided to get or set this attribute value int pthread_attr_getdetachstate const pthread_attr_t attr int detachstate int pthread_attr_setdetachstate pthread_attr_t attr int detachstate . The attribute value detachstate PTHREAD_CREATE_JOINABLE means that the return value of the thread is kept until it is joined by another thread. The attribute value detachstate PTHREAD_CREATE_DETACHED means that the .