strace showing _exit() vs exit_group()
Hi guys,
I'm struggling with the following program (sample.cpp): Code:
#include <stdio.h> When I run this program as shown above, the program 'hangs' -- meaning it runs, but never ends and returns back to the command prompt -- I have to Ctrl-C it. When I strace the program, the last thing it does is a _exit(0). However, if I comment out either the call to gtk_init(), OR, comment out the reference to MyLibraryFunction() (note that it's simplying referencing the function, it does not call it). -- the program terminates fine. When I strace this variant, I see that the last thing it does it a exit_group(0). Why the difference? I've been using the library MyLibrary with non-gtk apps for a while now, and they seem to work fine (they all seem to end with a exit_group). Now MyLibrary is a fairly complicated library, and it too references a number of other libraries. One of these libraries is pthreads, as it does utilize multi-threading. However, I believe all of the threading stuff is 'dynamic' -- only created at runtime (which isn't happening as we are not even calling into it). Anyways -- I believe the issue is somewhere in MyLibrary, but I was wondering if perhaps someone had some ideas of what to look for based on the _exit vs exit_group behavior I am seeing. For reference, here is my makefile... Code:
CXX=g++ Thanks /Paul |
gtk_init might start additional process(es) or thread(s)
use flag -f when strace-ing Note: I think you should add to your CPPFLAGS (or DEFINES in your case) Makefile-variable option -D_THREAD_SAFE |
gtk_init calls exit when it fails. That's why you see the particular behavior. gtk_init_check won't call exit, it will return false. gtk_init_with_args does the same but has an error parameter that might help. It contains a message field.
|
Thanks for the replies thus far.
NevemTeve --> I added the definition of the compile option _THREAD_SAFE as you suggested. SoftSprocekt --> What you stated sounded promising, but alas, it is not my problem. Both gtk_init and gtk_init_check are returning fine (in the latter case, it returns TRUE). In fact if I put a printf just before the return (0), it prints fine. The _exit(0) is coming from the return(0) of main()?? my quest continues... |
gtk_init might start additional process(es) or thread(s)
use flag -f when strace-ing |
NevemTeve,
I had read your initial comment, but didn't respond to it -- sorry about that. Yes, gtk_init might be creating some additional process(es) or thread(s), and I'm not calling any of the 'latter' gtk functions that might clean these up (such as gtk_main(). However, a more 'complete' gtk program is where I started when I discovered this error, using some simple and widly distributed gtk applications that did all of this stuff -- but my program continued to misbehave. I stripped it down to what you see here. Furthermore, if I comment our the reference to MyLibraryFunction, than the program runs fine; both gtk_init() and main() return as expected -- I get the exit_group that seems to be larger is scope (thread-wise). I also tried using the -f option for strace. Here is what I see at the very end ... Code:
8110 12:15:48 write(1, "Hello world\n", 12) = 12 Hmmm... that futex looks interesting... |
This suggest three processes (pid=8110,8111,8112)
|
Quote:
With that stated however, I've done more experimentation, and my example program now looks as follows: Code:
#include <stdio.h> Code:
CXX=g++ Incidentally, I also went back to try my more complete variant of the gtk program (one that actually has a gtk_main()), and it too will hang up main() if I add a call to pthread_exit(). Thanks |
the usual way is to use -pthread both for compiling and linking, otherwise there can be surprises (and do not use -lpthread). Probably the best thing is to use
Code:
CXX=g++ -pthread |
Well, I don't have gtk+-3.0; with gtk+2.0 it prints 'Hello world' and exits
end of strace log: Code:
write(1, "Hello world\n", 12Hello world |
oh yes, and your shared library should be compiled with -pthread too.
|
Quote:
Your test motivated me to try this same program on another Ubuntu platform. This new platform also has gtk+-3.0 on it BUT... it terminates correctly (with the exit_group). I need to look more closely at library versions on my initial machine. Thanks. |
just to know: exit is the usual way in a single-threaded app and exit_group is used by multithreaded ones. The behaviour is defined by the (existence of) -pthread.
|
Note: Of course it doesn't mean that user programs should use exit_group(2). It's up to exit(3) to call exit_group(2) if kernel-version if big enough.
|
All times are GMT -5. The time now is 08:28 AM. |