How it works...
We will define a variable called tid of the type pthread_t to store the thread identifier. A thread identifier is a unique integer, that is, assigned to a thread in the system. Before creating a thread, the message In main function is displayed on the screen. We will create a thread and pass the identifier tid to the pthread_create function. The thread is created with the default attributes, and the runThread function is set to execute to create the thread.
In the runThread function, we will display the text message Running Thread to indicate that the thread was created and is running. We will invoke a for loop to display the sequence of numbers from 1 to 5 through the running thread. By invoking the pthread_join method, we ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access