Hi, I have problem with boost.threads on linux ( under gcc ). I have a multithreaded aplication using Boost.Thread. It works just fine. However, I want to make a daemon out of it. So I tried to fork() at the start of the program and run all the relevant code ( including all threading ) in the child process. But when I do so, first call to create_thread hangs the process. I'm quite new to linux threading, so it is possible, that the problem is not related to Boost.Threads. Any hints? Thanks in advance. Pavol
Pavol Droba said:
Hi,
I have problem with boost.threads on linux ( under gcc ). I have a multithreaded aplication using Boost.Thread. It works just fine.
However, I want to make a daemon out of it. So I tried to fork() at the start of the program and run all the relevant code ( including all threading ) in the child process. But when I do so, first call to create_thread hangs the process.
I'm quite new to linux threading, so it is possible, that the problem is not related to Boost.Threads.
Several comments: 1) I'm not a POSIX/Linux developer either. 2) Since fork is non-standard and not part of Boost.Threads, you're technically in undefined territory as far as Boost.Threads is concerned. 3) Since Boost.Threads should play nice here, despite what I just said in (2), if there is a problem (see 1) it should be fixed. If anyone can shed light on this (and maybe even a patch), it would be appreciated. Other wise, I'll add this to my todo list, though it will be scored low. -- William E. Kempf
"William E. Kempf" wrote:
Pavol Droba said:
Hi,
I have problem with boost.threads on linux ( under gcc ). I have a multithreaded aplication using Boost.Thread. It works just fine.
However, I want to make a daemon out of it. So I tried to fork() at the start of the program and run all the relevant code ( including all threading ) in the child process. But when I do so, first call to create_thread hangs the process.
I'm quite new to linux threading, so it is possible, that the problem is not related to Boost.Threads.
Several comments:
1) I'm not a POSIX/Linux developer either.
2) Since fork is non-standard and not part of Boost.Threads, you're technically in undefined territory as far as Boost.Threads is concerned.
POSIX says "to avoid errors, the child process may only execute async- signal-safe operations until such time as one of the exec functions is called". As long as "create_thread" isn't async-signal-safe operation, he's in clear violating of POSIX "recomendation". Well, "long story": http://google.com/groups?selm=Ri_h9.10%24kX4.297082%40news.cpqcorp.net regards, alexander.
Pavol Droba
On Wed, Jul 02, 2003 at 02:36:26AM +0200, yg-boost-users@m.gmane.org wrote:
Pavol Droba
writes: | Hi, | | I have problem with boost.threads on linux ( under gcc ). | I have a multithreaded aplication using Boost.Thread. It works just fine. | | However, I want to make a daemon out of it. So I tried to fork() at the start | of the program and run all the relevant code ( including all threading ) in the | child process. But when I do so, first call to create_thread hangs the process.
I use something like this:
int main(int argc, char * argv[]) { pid_t pid = -1;
pid = fork();
if (pid > 0) { // Parent } else { if (pid == 0) { setsid(); close(0); close(1); close(2); chdir("/"); umask(0); } signal(SIGPIPE, SIG_IGN);
return child_main(); }
return EXIT_SUCCESS; }
(the code has been changed a bit, error handling removed etc.)
and in child_main threads are created.
It might be that you are just missing the setsid call?
-- Lgb
Thanks, I have already solved the problem. It was probably related to distro problem. Under my distribution of linux, pthread functionality is contained in some of the standard libraries, but it is broken. When I have linked explicitly with libphtread.a everything started to work. Regards, Pavol.
participants (4)
-
Alexander Terekhov
-
Pavol Droba
-
William E. Kempf
-
yg-boost-users@m.gmane.org