26 lines
532 B
Modula-2
Vendored
26 lines
532 B
Modula-2
Vendored
---
|
|
#include <stdlib.h>
|
|
#include <pthread.h>
|
|
|
|
typedef struct {
|
|
int d;
|
|
} TestStruct;
|
|
|
|
typedef struct {
|
|
void (*f)(TestStruct data);
|
|
} ThreadData;
|
|
|
|
void *dispatch(void *rawArg) {
|
|
ThreadData *arg = rawArg;
|
|
arg->f((TestStruct) {.d = 1});
|
|
return NULL;
|
|
}
|
|
|
|
void invokeFromThread(void (*f)(TestStruct data)) {
|
|
pthread_t thread_id;
|
|
ThreadData *threadData = malloc(sizeof(ThreadData));
|
|
threadData->f = f;
|
|
pthread_create(&thread_id, NULL, dispatch, (void *) threadData);
|
|
pthread_join(thread_id, NULL);
|
|
}
|