3#include "clod_thread_config.h"
4#include "thread_impl.h"
14 clod_process_main *main;
17int clod_process_stdthreads_main(
void *ptr) {
20 thread_args->main(args->arg_count, args->arg_vector);
25enum clod_process_result clod_process_start_stdthreads(
31 fprintf(stderr,
"libclod: clod_process_start_pthread: no thread main function given.\n");
33 return CLOD_PROCESS_INVALID;
37 fprintf(stderr,
"libclod: clod_process_start_stdthreads: given %d, but only CLOD_THREAD (1) is supported here.\n", opts->
type);
39 return CLOD_PROCESS_INVALID;
48 char *data = malloc(ALIGN(
sizeof(
struct thread_args), 16) + args_size(&args_in));
53 args_copy(args, &args_in);
56 const int res = thrd_create(&thrd, clod_process_stdthreads_main, data);
57 if (res != thrd_success) {
60 fprintf(stderr,
"libclod: pthread_create: %d\n", res);
62 if (res == thrd_nomem)
return CLOD_PROCESS_NO_MEMORY;
63 return CLOD_PROCESS_INVALID;
70 *process_out = &process->common;
75 return CLOD_PROCESS_OK;
80 const int res = thrd_join(stdthreads_process->thrd,
nullptr);
81 free(stdthreads_process);
82 if (res != thrd_success)
return CLOD_PROCESS_INVALID;
83 return CLOD_PROCESS_OK;
clod_process_main * main
Process entry point.
int arg_count
Number of arguments passed to main.
enum clod_process_type type
Type of process to create.