【发布时间】:2014-12-09 23:25:49
【问题描述】:
我已经对此进行了多次分析,但找不到导致它出现段错误的原因。也许我只是很密集,但我看不出这段代码不应该运行的原因。有没有人可以提供他们的见解?
#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");
}
}
【问题讨论】:
标签: c multithreading struct segmentation-fault pthreads