11th Chapter: Threading

Source: Internet
Author: User

pthread1, Introduction2, Threading Concepts3, indicating that the process ID is represented using the pid_t data type, and the thread ID is represented by the pthread_t data type. #include<pthread.h>intPthread_equal (pthread_t tid1, pthread_t Tid2);//used to compare two thread IDs for equalitypthread_t pthread_self (void);//the thread ID used by the thread to get itselfThe pthread_self function can be used with the Pthread_equal function when the thread needs to identify the data structure marked with the thread ID. For example, the main thread might put a work task in a queue and use the thread ID to control which jobs (P289-APUE) are processed by each worker thread. The main thread puts the new job into a work queue, and the thread pool of three threads moves out of the queue, each of which does not arbitrarily handle the job taken out of the top of the queue, but instead is assigned by the main thread program-controlled production, where the main thread puts the threading ID of the processing change job in the structure of each pending job. Each worker thread can only move out of a job labeled with its own thread ID. 4, thread creation # include<pthread.h>intPthread_create (pthread_t *restrict TIDP, const pthread_attr_t*restrict attr, void* (*START_RTN) (void), void *restrict arg);//Creating Threadssuccessful return 0, otherwise error encoding when Pthread_create is created successfully, the memory unit pointed to by TIDP is set to the thread ID of the newly created thread. The attr parameter is used to customize various thread properties. Now set to null the newly created thread runs from the START_RTN function, which has only one untyped pointer parameter arg, and if more than one parameter is required to pass to start_rnt, these parameters need to be placed in a struct, The address of this structure is then passed as an arg parameter to the example: Pthread_1.CPP

11th Chapter: Threading

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.