나는 이것을 여러 번 분석했는데 그 원인을 찾아 낼 수 없다. 아마 나는 밀도가 높을뿐입니다. 그러나이 코드가 실행되지 않아야하는 이유는 없습니다. 누구나 그들의 통찰력을 제공 할 수 있습니까?다음 코드의 구조체를 스레드로 전달하면 세그멘테이션 오류가 발생하는 이유는 무엇입니까?
#include <stdio.h>
#include <pthread.h>
typedef struct {
int a;
int b;
} struct1;
typedef struct {
struct1 s1;
} struct2;
void* thread_activity(void* v)
{
struct2 s2 = *((struct2*)v);
printf("%d\n", s2.s1.a);
return NULL;
}
int main(int argc, char* argv[])
{
struct1 s1;
s1.a = 10;
s1.b = 20;
struct2* s2;
s2->s1 = s1;
pthread_t tid;
if(pthread_create(&tid, NULL, thread_activity, s2)==0) {
printf("done\n");
}
}