When writing threaded code in C, I first have to create some struct
which includes all the arguments and a wrapper function. This leads to lots of code bloat and is not easy to read. See:
struct some_function_args {
int arg1;
int arg2;
int arg3;
};
void some_function_wrapper(struct some_function_args* args) {
some_function(args->arg1, args->arg2, args->arg3);
}
int main() {
struct my_args;
my_args.arg1 = 1;
my_args.arg2 = 2;
my_args.arg3 = 3;
pthread_create(..., some_function_wrapper, &my_args);
pthread_join(...);
}
Is there some kind of macro or library (maybe using varargs
) which automatically creates the needed structs and wrapper functions for me, like this? Or is this not possible at all in C?
int main() {
MY_THREAD thread = IN_THREAD {
some_function(1, 2, 3);
}
JOIN_THREAD(thread);
}