12.3 Thread Properties

Source: Internet
Author: User
Tags mutex


The Pthread interface allows us to fine-tune the behavior of threads and synchronous objects by setting properties associated with different objects. Typically, the functions that manage these properties conform to the following pattern:

    1. Each object has a Property object type associated with it (thread by thread property, mutex by mutex property, and so on), and a Property object can represent multiple properties. The Property object is opaque to the application, which means that the application and support for getting the Property object's internal structure can facilitate porting of the application. Instead, applications need to use functions to manage these properties.
    2. An initialization function is used to set the default value of the Property object;
    3. Another function is used to dispose of the Property object. If the initialization function assigns any resources associated with the Property object to the Property object, the function will release those resources;
    4. Each property is used by a function to get the property value of the Property object. The function returns 0 when it succeeds, returns an error number when it fails, and returns the value of the property returned by one of the parameters.
    5. Each property is used by a function to set a property value, in which case the value is passed in by the parameter value.
      In Chapter 11 we call the function Pthread_create program, we pass a null pointer to the parameter pthread_attr_t structure pointer. In fact, we can use the pthread_attr_t structure to more thread the default properties and associate them with the threads we create, we use the function Pthread_attr_init function to initialize the pthread_attr_t structure, and in the calling function Pthread After _attr_init, the pthread_attr_t structure will contain the default values for all of the thread properties that implement the support.
  
 
  1. #include <pthread.h>
  2. int pthread_attr_init(pthread_attr_t *attr);
  3. int pthread_attr_destroy(pthread_attr_t *attr);
  4. Both return: 0 if OK, error number on failure.

The function Pthread_attr_destroy will release the dynamic memory allocated at initialization and set the Property object to an invalid value, so if it is used incorrectly, the function Pthread_create will return an error.



From for notes (Wiz)

12.3 Thread Properties

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.