小编bor*_*tle的帖子

由pthread产生的Segfault?

我一直在墙上敲打几个小时,现在试图找出造成这一段错误的原因.

我发现segfault pthread_mutex_lock(lock)在线上一致地发生(38).我已经在锁定周围放置了两个打印语句,但是只有其中一个打印,这是我得出结论在该指令处发生段错误的理由.

我使用互斥正确锁紧,还是我做我的阵列错误(buffer[]numbermarker[]

#include <stdio.h>
#include <stdlib.h>
#include <pthread.h>

int* numbermarker = NULL;
int* buffer = NULL;
int pullposition = 0;
int placeposition = 1;
pthread_mutex_t *lock;
int ceiling;

/*This method places one of the primes in the buffer. It 
offers a safe way to manage where the next value will be placed*/
void placevalue(int value)
{
    buffer[placeposition] = value;
    placeposition++;
}

/*This method pulls the next prime and increments to the next prime …
Run Code Online (Sandbox Code Playgroud)

c pthreads segmentation-fault

1
推荐指数
1
解决办法
5761
查看次数

标签 统计

c ×1

pthreads ×1

segmentation-fault ×1