liveBook · Manning

Thrd_create

As explained in Modern C, Third Edition

thrd_create is a C11 threads-library function that creates and starts a new thread with a specified start routine.

thrd_create is the C11 <threads.h> function for creating and starting a thread. It receives a pointer to a thrd_t object, a thrd_start_t function pointer, and a void* argument passed to the new thread's start routine. The routine returns int; returning from it terminates the thread. section 20.0

Starting four game threads

A program can store thread identifiers in an array and start four routines that share the same game-state object: thrd_create(&thrd[0], update_thread, &L); thrd_create(&thrd[1], draw_thread, &L); thrd_create(&thrd[2], input_thread, &L); thrd_create(&thrd[3], account_thread, &L); Each routine receives the void* argument, converts it to a life* pointer, and performs its task concurrently with main and the other threads.

How Modern C, Third Edition covers it

How deep it goes
Defines the signature and callback contract, then demonstrates multiple calls and shared arguments without detailing scheduling internals.
Examples
Uses four game-task routines sharing one life object, followed by joins that wait for their termination.
What it assumes
Assumes familiarity with C function pointers, void pointers, structures, and basic concurrent execution.
What you can do after
Operate the C11 threads API to start routines, pass shared state, retain thread identifiers, and coordinate termination with thrd_join.
How it connects
Connects thrd_create with thrd_t, thrd_start_t, void pointers, and thrd_join.

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.