http://linuxgcc.sytes.net/sys017.php
わかりやすい。
基本、ヒープ領域を使うのがスレッドセーフにもなり安全。
void* threadfunc(void* p) { int a; struct data* pdata = (struct data*)p; a = pdata->a; ... free(pdata); } void func() { struct data* d = malloc(sizeof(struct data)); d->a = 10; pthread_create(thread, NULL, threadfunc, (void*)d); return; } int main() { func(); .... }
この場合はだれが確保したヒープ領域を削除するのか、ちゃんと設計しないと、解放したあとにアクセスしてしまうなどの間違いが生じるので注意。