Files
faumaray bba5c8a39a initial commit
Signed-off-by: Aleksey Selihov <faumaray@gmail.com>
2026-05-22 02:40:32 +03:00

18 lines
422 B
C

#include <pthread.h>
#include <stdint.h>
static void* worker(void* arg) {
return (void*)((intptr_t)arg * 2);
}
// Returns (input * 2) computed inside a spawned pthread.
int pthread_double(int x) {
pthread_t tid;
if (pthread_create(&tid, NULL, worker, (void*)(intptr_t)x) != 0)
return -1;
void* ret = NULL;
if (pthread_join(tid, &ret) != 0)
return -2;
return (int)(intptr_t)ret;
}