18 producer consumer model encoding and decoding

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: ttr t *attr, func *f, void *arg); returns: 0 if OK, non-zero on error The pthread create function creates a new thread and runs the thread routine f in the context of the new thread and with an input argument of arg. The attr argument can be used to change the default attributes of the newly created thread. However, changing these attributes is beyond our scope, and in our examples, we will always call pthread create with a NULL attr argument. When pthread create returns, argument tid contains the ID of the newly created thread. The new thread can determine its own thread ID by calling the pthread self function. #include <pthread.h> pthread t pthread self(void); returns: thread ID of caller 11.2.2 Terminating Threads A thread terminates in one of the following ways: ¯ ¯ The thread terminates implicitly when its top-level thread routine returns. The thread terminates explicitly by calling the pthread exit function, which returns a pointer to the return value thread return. If the main thread calls pthread exit, it waits for all other peer threads to terminate, and then terminates the main thread an...
View Full Document

Ask a homework question - tutors are online