liveBook · Manning

Threads.h

As explained in Modern C, Third Edition

threads.h is the C standard header that declares the C11 thread-management and thread-synchronization interfaces.

<threads.h> is the C11 standard header for creating threads and waiting for their termination. A thread follows its own control flow and may execute simultaneously or through interleaving, depending on the platform. section 20.0

Creating and joining four threads

A game stores shared state in a life object, passes its address to four thread functions, and records their opaque thrd_t identifiers. Each function matches thrd_start_t, accepting void* and returning int. main later calls thrd_join for each identifier, allowing the threads to finish before the program proceeds. section 20.0

#include <threads.h>
typedef int (*thrd_start_t)(void*);
int thrd_create(thrd_t*, thrd_start_t, void*);
int thrd_join(thrd_t, int *);

Use the declaration listing to inspect thrd_start_t, thrd_create, thrd_t, and thrd_join together. section 20.0

How Modern C, Third Edition covers it

How deep it goes
Defines the central declarations and demonstrates their use, but does not develop synchronization mechanisms beyond the shown thread lifecycle.
Examples
Uses a game with update, drawing, input, and accounting threads operating on one life object.
What you can do after
Apply it via <threads.h> to create threads, pass task data, collect identifiers, and join completed threads.
How it connects
Connects threads with concurrency, function pointers, opaque types, shared state, and thread joining.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Modern C, Third Edition. The section links point to the parts of the book it draws on.