1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39
|
struct STestA
{
int varA;
};
struct STestB
{
int varB;
};
void * test( void * args )
{
printf("Arg1 -> %d\n", ((struct STestA *)args)[0].varA);
printf("Arg2 -> %d\n", ((struct STestB *)args)[1].varB);
return NULL;
}
int main( int argc, char ** argv )
{
pthread_t pthread_id;
struct STestA TestA;
struct STestB TestB;
void * args = malloc(sizeof(struct STestA) + sizeof(struct STestB));
TestA.varA = 10;
TestB.varB = 20;
memcpy(args, &TestA, sizeof(struct STestA));
memcpy(args + sizeof(struct STestA), &TestB, sizeof(struct STestB));
pthread_create(&pthread_id, NULL, test, args);
pthread_join(pthread_id, NULL);
free(args);
args = NULL;
return EXIT_SUCCESS;
} |