linux-sysprog · advanced · ~15 min
Collect a thread's result via join's value pointer.
Implement long square_in_thread(long v) that runs a thread which returns v*v through the thread return value, retrieves it with pthread_join, and returns it.
#include <pthread.h>
long square_in_thread(long v) {
/* TODO */
return 0;
}
Solve this exercise in the browser editor — compile and run against the test harness, no setup required.