c - Multithreading in Windows - Error in creating array of function pointers -
i beginner in multithreading(windows). want create 2 threads using createthread function in loop. 2 threads functions want spawn different. creating array of function pointers store 2 functions want spawn. use array values in lpstartaddress parameter of create thread function. getting error in creating array of function pointers. have post significant part of code below. please correct mistake , me create array of function pointers (whose functions going spawned threads). in advance.
dword winapi threadproc1(lpvoid lparam) { print_func(getcurrentthreadid(),(lpdword)lparam); return 1; } dword winapi threadproc2(lpvoid lparam) { print_func(getcurrentthreadid(),(lpdword)lparam); return 1; } int main() { handle hthread[max_threads] = {null};//max_threads=2 dword dwthreadid; /* array of lparam */ dword dwarrayparam[param_max] = {1,2};//param_max=2 /* array of function ptrs */ typedef dword winapi (*t_threadproc)(lpvoid);//error in line t_threadproc threadproc[max_threads] = {threadproc1,threadproc2}; for(int i=0; i<max_threads; i++) { hthread[i] = createthread(null,//security attributes 0,//stack size threadproc[i],//thread start address (dwarrayparam+i), 0, &dwthreadid ); } }
compilation error: error iam getting error c2059: syntax error : '(' if remove calling convention winapi iam getting error in next line error c2440: 'initializing' : cannot convert 'dword (__stdcall *)(lpvoid)' 't_threadproc'
i believe line should this:
typedef dword (winapi *t_threadproc)(lpvoid);
i.e. keyword winapi
needs inside parenthesis.
Comments
Post a Comment