Re: gnome_show_url() hangs in threaded programs




On 2001.08.22 21:52 Pawel Salek wrote:
> I have impression that something has got broken in gnome_show_url() and
> related functions (or perhaps, a bug has surfaced that has not been
> active earlier).

After closer investigation, I think the problem is in gthread library. I
attach a test program with does some threading and forking at the same
time. 
The program WorksForMe(TM) when compiled as follows:
# cc atfork-test.c -lthread

The program hangs when compiled as follows:
# cc atfork-test.c -lgthread -lglib

I think it should not happen so (and gnome programs hang because they link
against gthread). Can someone confirm it? Offer a solution?

/Pawel


/* Pawel Salek, pawsa@theochem.kth.se, 2001-08-23

   Rest of pthread_atfork() function.

   The program WorksForMe(TM) when compiled as follows:
   cc atfork-test.c -lthread

   The program hangs when compiled as follows:
   cc atfork-test.c -lgthread -lglib
*/
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/wait.h>
#include <pthread.h>

void* my_thread(void*a)
{
    int i;
    for(i=0; i<5; i++) {
	printf("mythread, i=%i\n", i);
	sleep(2);
    }
    return NULL;
}

void prepare_parent()
{
    printf("ATFORK: prepare_parent\n");
}

void resume_parent()
{
    printf("ATFORK: resume_parent\n");
}

void resume_child()
{
    printf("ATFORK: resume_child\n");
}

int main(int argc, char* argv[])
{
    pthread_t a_thread;
    pid_t pid;
    void* ret;
    int status;

    pthread_atfork(prepare_parent, resume_parent, resume_child);
    pthread_create(&a_thread, NULL, my_thread, NULL);

    sleep(1);
    switch( (pid=fork()) ) {
    case 0: printf("Child is here\n"); exit(0); break;
    case -1: printf("Fork failed\n"); break;
    default: printf("Parent, waiting for child %i\n", pid);
	wait(&status);
    }
    printf("Main thread waits for the thread to join.\n");
    pthread_join(a_thread, &ret);
    return 0;
}



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]