8000 Thread lock with MinGW and a JVM · Issue #340 · log4cplus/log4cplus · GitHub
[go: up one dir, main page]

Skip to content

Thread lock with MinGW and a JVM #340

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
aaron-bray opened this issue Sep 6, 2018 · 4 comments
Closed

Thread lock with MinGW and a JVM #340

aaron-bray opened this issue Sep 6, 2018 · 4 comments
Assignees
Labels
de-/initialization issues dealing with initialization or deinitialization
Milestone

Comments

@aaron-bray
Copy link

The ThreadPool deconstruction hangs on 'condition_consumers.notify_all();'

I am using log4cplus as part of my C++ library.
I have JNI bindings to provide usage of my library through Java
The Java app does a load library for linkage with my C++ app
When the Java app finishes, and deconstructs everything, the jvm hangs and will not exit
If I comment out the condition_consumers.notify_all(); line, everything deconstructs and the jvm exits
This only occurs when I build log4cplus on windows 10 using mingw-64
(msvc 2015,2017, osx clang, ubuntu gcc all deconstruct fine)

I have not had any issues with native C++ applications built with mingw hanging at program deconstruction, but I will confirm this and ensure the ThreadPool dtor does indeed complete. (I assume it will, and this is some weird JVM/mingw thread disagreement)

To reproduce this,

I pulled 5ce831b
Using cmake 3.8.1, I turned off WITH_UNIT_TESTS, LOGGINGSERVER, TESTING, DECORATION
I built the log4cplus.dll using mingw-64 version 8.1 and 7.3 from the latest mingw-w64 download from sourceforge
I then run this simple Java (Java x64 1.8.0_131) program:

package kitware.physiology.pulse;

public class QuickLoad 
{
  public static void main(String[] args) 
  {
    System.load("C:/Programming/builds/log4cplus-mingw7/bin/liblog4cplus.dll");
    //System.load("C:/Programming/builds/log4cplus-mingw8/bin/liblog4cplus.dll");
    System.out.println("I am done!");
  }
}

I am running this simple driver via eclipse neon, and the jvm never exits
I am not calling the initialize logger or anything, just loading the dll and exiting

This is on my Surface Pro 3, x64,
(Note other users have reported this, not sure about their platform other than mingw on windows 7)

@aaron-bray
Copy link
Author

Confirmed a C++ native application compiled with mingw has no issues in deconstruction
Seems to be something due to running inside a JVM (also update to 1.8_181)

@wilx wilx self-assigned this Sep 6, 2018
@wilx
Copy link
Contributor
wilx commented Sep 6, 2018

This is likely because it does not get deinitialized properly. It initializes automatically but the deinitialization has to happen outside DllMain() on some platform combinations. Please try to deinitialize it by creating log4cplus::Initializer instance and make sure it is deleted or destroyed before your try to unload the DLL.

I just took a look at the code and it seems to me this is currently the only way. I should probably add a log4cplus::deinitialize() counterpart for the log4cplus::initialize() to make the deinitialization possible without the log4cplus::Initializer instance.

@wilx wilx added this to the v2.0.3 milestone Sep 6, 2018
@wilx wilx added the de-/initialization issues dealing with initialization or deinitialization label Sep 6, 2018
@wilx
Copy link
Contributor
wilx commented Sep 6, 2018

This should help if you cannot create class instances easily: 25185bc

@aaron-bray
Copy link
Author

This is working great!
There are sometimes when I load my library and don't create an Initializer
so this is exactly what I needed
I just added this to my JNI clean up interface and everything is shutting down fine now
Thanks for the quick support!

@wilx wilx closed this as completed Sep 14, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
de-/initialization issues dealing with initialization or deinitialization
Projects
None yet
2F61 Development

No branches or pull requests

2 participants
0