How it works...
We will start by defining a macro called max of the value 10. Then, we will define an array stack of the size max. We will define two mutex objects with the names pop_mutex and push_mutex.
To use the stack, the value of top will be initialized to -1. We will define two variables of the type pthread_t, with the names tid1 and tid2, to store two thread identifiers.
We will invoke the pthread_create function to create the first thread and assign the identifier returned by the function to the variable tid1. The thread will be created with the default attributes, and the push function will be executed to create this thread.
We will invoke the pthread_create function a second time to create the second thread, and we'll assign the ...
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