c++ - pass the argv and argc to thread -


my program receives arguments user

int main(int argc, char *argv[]) 

and have function inside thread (i can't change function):

func (&argc, &argv); 

as can see, need call the thread, , inside thread, call func parameters. saw there way sent thread multiple parameters struct.

but how struct suppose looks like? , how copy parameters struct?

thanks!

struct arg_holder {     int argc;     char ** argv; };  void * thread_caller(void * arg) {     struct arg_holder arg_struct = *(struct arg_holder *)arg;     free(arg);     return func(arg_struct->argc, arg_struct->argv); } 

in main:

struct arg_holder * arg_struct = malloc(sizeof(*arg_struct)); arg_struct->argc = argc; arg_struct->argv = argv;  pthread_create(&thread_id, null, thread_caller, arg_struct); 

Comments

Popular posts from this blog

html - Sizing a high-res image (~8MB) to display entirely in a small div (circular, diameter 100px) -

java - IntelliJ - No such instance method -

identifier - Is it possible for an html5 document to have two ids? -