From: Roman Prokhorov <roma@stalker.gamma.ru>
Subject: fork() problem
Date: Thu, 29 Aug 2002 03:13:18 +0400 [thread overview]
Message-ID: <roma-48B9E8.03131729082002@news.gamma.ru> (raw)
Hi,
I have a problem: Under Tru64 the fork() called from a thread freezes.
This doesn't happen on the other Unixes I tried. See my code below, did
I do anything wrong?
I discovered that I can unfreeze the fork() when I call sleep() from the
main thread. What sleep() realy does?
#include<stdio.h>
#include<stdlib.h>
#include<pthread.h>
#include <sys/types.h>
#include<unistd.h>
void fork_handler1() {
printf("prepare handler called\n");
}
void fork_handler2() {
printf("parent handler called\n");
}
void fork_handler3() {
printf("child handler called\n");
}
void func(void *pData) {
pthread_atfork(fork_handler1,fork_handler2,fork_handler3);
printf("thread launched\n");
if(fork()==0) {
printf("new fork started, pid=%d\n",getpid());
exit(0);
} else {
printf("old fork running, pid=%d\n",getpid());
}
}
main() {
char buf[10];
pthread_t theThread;
if(!pthread_create(&theThread,NULL,(void *(*)(void *))&func,NULL)) {
pthread_detach(theThread);
} else {
printf("Unable to launch a thread\n");
}
printf("hit Enter, please\n");
fgets(buf,sizeof(buf),stdin);
//sleep(1);
printf("hit Enter again, please\n");
fgets(buf,sizeof(buf),stdin);
}
--
Roman
next reply other threads:[~2002-08-28 23:13 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2002-08-28 23:13 Roman Prokhorov [this message]
2002-08-29 4:04 ` fork() problem Paul Pluzhnikov
2002-08-29 15:00 ` Roman Prokhorov
2002-08-30 0:05 ` Paul Pluzhnikov
2002-08-30 12:28 ` Roman Prokhorov
2002-08-30 15:04 ` Paul Pluzhnikov
2002-08-30 16:41 ` Roman Prokhorov
2002-08-30 18:04 ` Paul Pluzhnikov
read-only archive
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox