Uploaded image for project: 'Log4cxx'
  1. Log4cxx
  2. LOGCXX-554

Child thread does not inherit a copy of the mapped diagnostic context of its parent

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Won't Fix
    • 0.12.1, 0.13.0
    • 0.12.1, 0.13.0
    • None
    • None
    • Linux - red hat 8.3/Windows 10/ Windows server 2016 64 bit

    Description

      Hi,

       

      The API documentation for MDC says "The MDC is managed on a per thread basis. A child thread automatically inherits a copy of the mapped diagnostic context of its parent."

      However this does not appear to be the case. Take the following testcase:

      #include <iostream>
      #include <pthread.h>
      #include <log4cxx/mdc.h>

      using namespace std;

      void *threadfunc(void *arg)

      { std::cout << "child: " << log4cxx::MDC::get("mykey") << std::endl; }

      int main(int argc, char *argv[])

      { pthread_t thread_id; log4cxx::MDC::put("mykey", "123"); std::cout << "main: " << log4cxx::MDC::get("mykey") << std::endl; pthread_create(&thread_id, NULL, threadfunc, NULL); pthread_join(thread_id, NULL); return 0; }

       

      The resulted output is:

      main: 123
      child:

       

      Instead of:

      main: 123
      child: 123

       

      This simple program was executed on red hat 8.3 (used  c++17 and log4cxx 0.12.1)

      For compiling this simple program I used the following command line:

      g++ -std=c++17 -D_GLIBCXX_USE_CXX11_ABI=0 -I log4cxx_path/include -L log4cxx_path/lib/ -llog4cxx -L apr-util_path/lib/ -laprutil-1 -L apr_path/lib/ -lapr-1 -pthread -o test_mdc test_mdc.cpp

      This issue also happens on windows 64 bit in our applications (log4cxx 0.12.1) and I have found the same issue reported under this jira: LOGCXX-339 (and also is known on web as a latent problem)

      I checked the release notes of log4cxx 0.13.0 and it does not seem to address this issue and probably it was never fixed cause the resolution for the issue stated above was supposed to be fixed in the new versions.

       

      Could you check this on the latest log4cxx (0.13.0)? and if is still happening please provide a solution.

       

      Thanks,

      Stefan Jipa

      Attachments

        Activity

          People

            Unassigned Unassigned
            stefanjipa Stefan Jipa
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: