BUGFIX: Fix a possible deadlock if an error occurs

This commit is contained in:
Thomas Preud'homme 2009-06-25 13:42:41 +02:00 committed by Thomas Preud'homme
parent 177e548efe
commit c9323cd901
4 changed files with 19 additions and 4 deletions

View File

@ -47,12 +47,13 @@ int get_thread_number(void)
int init_producer_thread(void)
{
int i_local;
int thread_num;
i_local = get_thread_number();
if (init_thread_comm(&tcomms[i_local]))
thread_num = get_thread_number();
if (init_thread_comm(&tcomms[thread_num]))
{
error = 1;
pthread_cond_signal(&init_cond);
return -1;
}
pthread_mutex_lock(&init_lock);

View File

@ -17,7 +17,11 @@ int init_thread_comm(struct thread_comm *comm)
{
int flags;
pipe(pipefd);
if (pipe(pipefd))
{
fprintf(stderr, "Unable to create a pipe for pipe communication\n");
return -1;
}
flags = fcntl(pipefd[READ_IDX], F_GETFL);
fcntl(pipefd[READ_IDX], F_SETFL, flags | O_NONBLOCK);
comm->pipefd = pipefd;

View File

@ -16,6 +16,11 @@ __thread volatile int prod_idx = 0;
int init_thread_comm(struct thread_comm *comm)
{
shared_space = (volatile void **) malloc(SHARED_SPACE_SIZE);
if (shared_space == NULL)
{
fprintf(stderr, "Unable to allocate space for shared mem communication\n");
return -1;
}
comm->shared_space = shared_space;
comm->cons_idx = &cons_idx;
comm->prod_idx = &prod_idx;

View File

@ -16,6 +16,11 @@ __thread volatile int prod_idx = 0;
int init_thread_comm(struct thread_comm *comm)
{
shared_space = (volatile void **) malloc(SHARED_SPACE_SIZE);
if (shared_space == NULL)
{
fprintf(stderr, "Unable to allocate space for shared mem communication\n");
return -1;
}
comm->shared_space = shared_space;
comm->cons_idx = &cons_idx;
comm->prod_idx = &prod_idx;