Hello, Zephyr world!

Define a native k_thread at compile time and join it via pthread_join().

Overview

This sample demonstrates the 1:1 mapping between Zephyr kernel threads and POSIX threads. A k_thread is statically defined with K_THREAD_DEFINE() (deferred start), then started at runtime and joined using pthread_join(). The thread’s return value, set with k_thread_result_set(), is retrieved through the standard POSIX interface.

This pattern is useful for safety-critical applications where dynamic memory allocation is prohibited: the thread and its stack are allocated at compile time, yet the application can still use the POSIX threading API for synchronization.

Building and Running

west build -b native_sim samples/posix/hello_zephyr
west run

Sample Output

Hello World! native_sim from k_thread 0x...
k_thread returned 42