linux-sysprog · advanced · ~15 min

Double a value in a thread

Pass an argument into a thread safely.

Challenge

Implement long double_in_thread(long v) that starts one thread, passes v to it (by pointer), has the thread double it, joins, and returns the doubled value.

Starter code

#include <pthread.h>

long double_in_thread(long v) {
    /* TODO */
    return 0;
}

Solve this exercise in the browser editor — compile and run against the test harness, no setup required.