c将几个参数传递给线程(c passing several arguments to threads)
当我创建一个线程时,我想传递几个参数。 所以我在头文件中定义以下内容:
struct data{ char *palabra; char *directorio; FILE *fd; DIR *diro; struct dirent *strdir;
};
在.c文件中,我执行以下操作
if (pthread_create ( &thread_id[i], NULL, &hilos_hijos, ??? ) != 0){ perror("Error al crear el hilo. \n"); exit(EXIT_FAILURE); }
我如何将所有这些参数传递给线程。 我虽然说:
1)首先使用malloc为此结构分配内存,然后为每个参数赋值:
struct data *info info = malloc(sizeof(struct data)); info->palabra = ...;
2)定义
struct data info info.palabra = ... ; info.directorio = ...;
然后,我如何在线程中访问这些参数void thread_function(void * arguments){??? }
提前致谢
when i create a thread, i want to pass several arguments. So i define in a header file the following:
struct data{ char *palabra; char *directorio; FILE *fd; DIR *diro; struct dirent *strdir;
};
In a .c file i do the following
if (pthread_create ( &thread_id[i], NULL, &hilos_hijos, ??? ) != 0){ perror("Error al crear el hilo. \n"); exit(EXIT_FAILURE); }
How do i pass all this arguments to the threads. I though about:
1) first use malloc to allocate memory for this structure and then give each parameter a value:
struct data *info info = malloc(sizeof(struct data)); info->palabra = ...;
2) define
struct data info info.palabra = ... ; info.directorio = ...;
and then, how do i access these parameters in the thread void thread_function ( void *arguments){ ??? }
thanks in advance
原文:https://stackoverflow.com/questions/11162613
最满意答案
您是否可以在点击发票时将目标空白添加到表单?:
$("#invoice").click(function(){ $('#form_id').attr('target', '_blank'); });
要么:
$(document).on("click","#invoice",function(){ $('#form_id').attr('target', '_blank'); });
could you not add target blank to the form when invoice is clicked?:
$("#invoice").click(function(){ $('#form_id').attr('target', '_blank'); });
or:
$(document).on("click","#invoice",function(){ $('#form_id').attr('target', '_blank'); });