commit
bba5c8a39a
109 files changed
+14085
No files matched your search
@@ -0,0 +1,17 @@
|
||||
#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;
|
||||
}
|
||||
Reference in new issue
Block a user