Print Page | Close Window

GdiPlus Registering Race Condition

Printed From: Codejock Forums
Category: Codejock Products
Forum Name: Toolkit Pro
Forum Description: Topics Related to Codejock Toolkit Pro
URL: http://forum.codejock.com/forum_posts.asp?TID=23703
Printed Date: 23 December 2024 at 3:24am
Software Version: Web Wiz Forums 12.04 - http://www.webwizforums.com


Topic: GdiPlus Registering Race Condition
Posted By: mgampi
Subject: GdiPlus Registering Race Condition
Date Posted: 03 September 2018 at 6:07am
Hello,

when creating two different CXTPMarkupContexts both call in their constructor the function CXTPMarkupDrawingContext::Register(TRUE). As this leads to a registering of the CXTPSingleton CXTPGdiPlus 2x sometimes an assertion will be caused, when we got a bad timing.

Can anyone please help me solve this issue by fixing the race condition or telling me if I've used these classes in a wrong way and how to use them correctly?

Thanks for the help in advance.


-------------
Martin

Product: Xtreme Toolkit v 22.1.0, new Projects v 24.0.0
Platform: Windows 10 v 22H2 (64bit)
Language: VC++ 2022



Replies:
Posted By: agontarenko
Date Posted: 05 September 2018 at 3:56am
Hello Martin, how I can reproduce it with our samples?

Regards,
Artem Gontarenko


Posted By: mgampi
Date Posted: 05 September 2018 at 5:27am
Hello,

the easiest way would be to implement a sample that uses multithreading and do something like the following all the time until you get into the race condition:

  CSampleMarkupView* Wnd_ = new CSampleMarkupView(); //Calls CXTPMarkupDrawingContext::Register(TRUE) -> calls CXTPGdiPlus::Register(TRUE)
  // with ASSERT(m_nGdiplusToken == 0 && m_hModule == 0) (XTPGdiPlus.cpp Line 61)
 
  delete Wnd_; //Calls CXTPMarkupDrawingContext::Register(FALSE) -> calls CXTPGdiPlus::Register(FALSE)
  /*
    XTPGdiPlus.cpp Line 75ff:
      m_nCount--;

      if (m_nCount != 0)
      return;
      -----------------> if another thread that wants to call CXTPMarkupDrawingContext::Register(TRUE) interrupts our thread we got an assertion (ASSERT(m_nGdiplusToken == 0 && m_hModule == 0)) in XTPGdiPlus.cpp Line 61

      if (m_hModule)
      {
        // Termination of background thread, which is causing the shutdown problem.
        gdiplusStartupOutput.NotificationUnhook(m_nGdiplusToken);
        GdiplusShutdown(m_nGdiplusToken);
        FreeLibrary(m_hModule);
      }
      m_hModule = NULL;
      m_nGdiplusToken = 0;
   */


using:
class CSampleMarkupView : public CWnd, CXTPMarkupContext {
public:
  CSampleMarkupView() : CWnd(), CXTPMarkupContext() {}
  virtual ~CSampleMarkupView() {}
};

Best regards



-------------
Martin

Product: Xtreme Toolkit v 22.1.0, new Projects v 24.0.0
Platform: Windows 10 v 22H2 (64bit)
Language: VC++ 2022


Posted By: mgampi
Date Posted: 05 September 2018 at 6:34am
Fixed it.
Thanks for the help! :)


-------------
Martin

Product: Xtreme Toolkit v 22.1.0, new Projects v 24.0.0
Platform: Windows 10 v 22H2 (64bit)
Language: VC++ 2022


Posted By: Marco1
Date Posted: 10 September 2018 at 1:21pm
Was this problem related to your program?


-------------
Product: XTP 18.3.0 on VS 2017
Platform: VS 2017 / Windows 10 (64bit)


Posted By: mgampi
Date Posted: 10 September 2018 at 1:23pm
Yes!

It's been my fault...


-------------
Martin

Product: Xtreme Toolkit v 22.1.0, new Projects v 24.0.0
Platform: Windows 10 v 22H2 (64bit)
Language: VC++ 2022



Print Page | Close Window

Forum Software by Web Wiz Forums® version 12.04 - http://www.webwizforums.com
Copyright ©2001-2021 Web Wiz Ltd. - https://www.webwiz.net