Current-Users archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

atexit(), dlclose() and more atexit()



I have at hand a program (the current svn trunk of VICE, to be exact)
which does the following:

1. In the original thread, it dlopen()s libavformat.
2. libavformat establishes an atexit() handler.
3. The main thread starts a new thread, and registers an atexit()
   handler to clean up that thread.
4. main thread exit()s.
5. atexit() handler obtains its lock, and calls the handler established in 3.
6. said handler tells the new thread to clean up and finish. One of the last
   things the thread does, is to dlclose() libavformat.
7. libavformat's atexit handling gets called, which tries to obtain the
   same lock that was already obtained, in a different thread, in step
   5.
8. deadlock.

Who is in the wrong here?
 
Some stack traces for illustration.
A more extensive version of this can be found at the bugtracker of VICE:
https://sourceforge.net/p/vice-emu/bugs/1243/

See Thread 9 frame #3 versus Thread 1 frame #4

the "new thread":

Thread 9 (LWP 9 of process 2731):
#0  0x000075e643aa1f7a in ___lwp_park60 () from /usr/lib/libc.so.12
#1  0x000075e6440095a6 in pthread__mutex_lock_slow (ptm=ptm@entry=0x75e643fe1780 <__atexit_mutex>, ts=ts@entry=0x0) at /usr/src/lib/libpthread/pthread_mutex.c:384
#2  0x000075e6440099b5 in pthread_mutex_lock (ptm=ptm@entry=0x75e643fe1780 <__atexit_mutex>) at /usr/src/lib/libpthread/pthread_mutex.c:208
#3  0x000075e643b43a14 in __cxa_finalize (dso=0x75e638e145e0 <__dso_handle>) at /usr/src/lib/libc/stdlib/atexit.c:198
#4  0x000075e638a397f8 in ?? () from /usr/pkg/lib/ffmpeg4/libavformat.so.58
#5  0x000075e64b546160 in ?? ()
#6  0x000075e638b8aed9 in _fini () from /usr/pkg/lib/ffmpeg4/libavformat.so.58
#7  0x0000000000000000 in ?? ()

the main thread:

Thread 1 (LWP 1 of process 2731):
#0  0x000075e643aa1f7a in ___lwp_park60 () from /usr/lib/libc.so.12
#1  0x000075e64400a71f in pthread_cond_timedwait (cond=0x75e62dd910c0, mutex=0x75e62dd91018, abstime=0x0) at /usr/src/lib/libpthread/pthread_cond.c:168
#2  0x000075e64400c2c8 in pthread_join (thread=0x75e62dd91000, valptr=valptr@entry=0x0) at /usr/src/lib/libpthread/pthread.c:724
#3  0x00000000004312ec in vice_thread_shutdown () at ../../vice/src/main.c:350
#4  0x000075e643b43ac0 in __cxa_finalize (dso=dso@entry=0x0) at /usr/src/lib/libc/stdlib/atexit.c:222
#5  0x000075e643b437b3 in exit (status=status@entry=0) at /usr/src/lib/libc/stdlib/exit.c:60
#6  0x0000000000445998 in archdep_vice_exit (excode=excode@entry=0) at ../../../../vice/src/arch/shared/archdep_atexit.c:119
#7  0x00000000005ca086 in ui_exit () at ../../../../vice/src/arch/gtk3/ui.c:2051
#8  0x00000000005cb4e4 in ui_close_callback (widget=<optimized out>, user_data=<optimized out>) at ../../../../vice/src/arch/gtk3/uicommands.c:226
#9  0x000075e64878550c in _gtk_marshal_BOOLEAN__OBJECT_UINT_FLAGS () from /usr/pkg/lib/libgtk-3.so.0
#10 0x000075e645c12352 in g_closure_invoke () from /usr/pkg/lib/libgobject-2.0.so.0
#11 0x000075e645c233f0 in signal_emit_unlocked_R () from /usr/pkg/lib/libgobject-2.0.so.0
#12 0x000075e645c2d61e in g_signal_emit_valist () from /usr/pkg/lib/libgobject-2.0.so.0
#13 0x000075e645c2e3cc in g_signal_emit () from /usr/pkg/lib/libgobject-2.0.so.0
#14 0x000075e6484f906f in gtk_accel_group_activate () from /usr/pkg/lib/libgtk-3.so.0
#15 0x000075e6484fa6a6 in gtk_accel_groups_activate () from /usr/pkg/lib/libgtk-3.so.0
#16 0x000075e648759a9a in gtk_window_activate_key () from /usr/pkg/lib/libgtk-3.so.0
#17 0x00000000005c8453 in kbd_event_handler (w=0x75e64b450260, report=0x75e64cc7bd00, gp=<optimized out>) at ../../../../vice/src/arch/gtk3/kbd.c:366
#18 0x000075e648784873 in _gtk_marshal_BOOLEAN__BOXED () from /usr/pkg/lib/libgtk-3.so.0
#19 0x000075e645c12352 in g_closure_invoke () from /usr/pkg/lib/libgobject-2.0.so.0
#20 0x000075e645c233f0 in signal_emit_unlocked_R () from /usr/pkg/lib/libgobject-2.0.so.0
#21 0x000075e645c2d61e in g_signal_emit_valist () from /usr/pkg/lib/libgobject-2.0.so.0
#22 0x000075e645c2e3cc in g_signal_emit () from /usr/pkg/lib/libgobject-2.0.so.0
#23 0x000075e648738907 in gtk_widget_event_internal () from /usr/pkg/lib/libgtk-3.so.0
#24 0x000075e64861332c in propagate_event () from /usr/pkg/lib/libgtk-3.so.0
#25 0x000075e648614f44 in gtk_main_do_event () from /usr/pkg/lib/libgtk-3.so.0
#26 0x000075e64802c9ae in _gdk_event_emit () from /usr/pkg/lib/libgdk-3.so.0
#27 0x000075e64805ac44 in gdk_event_source_dispatch () from /usr/pkg/lib/libgdk-3.so.0
#28 0x000075e645849543 in g_main_context_dispatch () from /usr/pkg/lib/libglib-2.0.so.0
#29 0x000075e6458496fc in g_main_context_iterate.isra () from /usr/pkg/lib/libglib-2.0.so.0
#30 0x000075e64584997a in g_main_loop_run () from /usr/pkg/lib/libglib-2.0.so.0
#31 0x000075e6486142f2 in gtk_main () from /usr/pkg/lib/libgtk-3.so.0
#32 0x0000000000634b7c in main (argc=1, argv=0x7f7fff1e0628) at ../../../../vice/src/arch/gtk3/gtk3main.c:91


Attachment: signature.asc
Description: PGP signature



Home | Main Index | Thread Index | Old Index