Overview
Features
Download
Documentation
Community
Add-Ons & Services

NDC & Multithreading

Please post support and help requests here.
D503
Posts: 2
Joined: 12 Oct 2012, 10:08

NDC & Multithreading

Postby D503 » 12 Oct 2012, 11:10

Hi,
I think there is a bug in NestedDiagnosticContext or ThreadLocalStorage. Example code

Code: Select all

#include <Poco/NestedDiagnosticContext.h>
#include <Poco/Thread.h>
#include <Poco/RunnableAdapter.h>


struct Dummy
{
   void f()
   {
      poco_ndc(f);
      Poco::Thread::sleep(1000);
   }
};

int main(int argc, char** argv[])
{
   Dummy d;
   Poco::RunnableAdapter<Dummy> ra(d, &Dummy::f);
   for (;;)
   {
      Poco::Thread th;
      th.start(ra);
      Poco::Thread::sleep(100);
   }
   return 0;
}

causes Access Violation deep in NDCScope destructor. I use Visual Studion 2008 compiler. Unfotunatly, Im not very expirienced in concurrency in C++ and can't find bug by myaself. Any idea how to fix it?

guenter
Posts: 1178
Joined: 11 Jul 2006, 16:27
Location: Austria

Re: NDC & Multithreading

Postby guenter » 12 Oct 2012, 15:43

There's a bug in your code. Your local Thread object in the loop will go out of scope and be destroyed before the thread will actually be started, causing the access violation.

D503
Posts: 2
Joined: 12 Oct 2012, 10:08

Re: NDC & Multithreading

Postby D503 » 15 Oct 2012, 02:37

Ok, now i see, tanks


Return to “Support”

Who is online

Users browsing this forum: No registered users and 2 guests

cron