Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Other Discussions
  3. The Weird and The Wonderful
  4. When things to more than you think

When things to more than you think

Scheduled Pinned Locked Moved The Weird and The Wonderful
javascripthelpannouncementc++com
2 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • I Offline
    I Offline
    imagiro
    wrote on last edited by
    #1

    I just spent nearly two days debugging an COM exe server using ATL and boost. There is a boost thread, acting as an asynchronous task manager that gets task queued which do callbacks into COM objects (into JScript objects). The thread was hanging in join(), even though a breakpoint set at the end of the thread function was hit. The code was written by a collegue, who is a god with boost, but rather new to ATL - and he hates it. Me in turn did not use a lot of boost (yet), but with COM/ATL I have quite some experience, and I like it. So first I suspected boost to be somehow buggy, although I could not really imagine that such a widely used thing like boost::thread would have such a serious bug or a somehow screwed functionality. Here is (shortened) how the thread looks:

    void operator()()
    {
    CoInitializeEx(NULL, COINIT_APARTMENTTHREADED);
    BOOST_SCOPE_EXIT_ALL(&) { CoUninitialize(); };
    try {
    // lots of code here...
    // e.g. running a task from a task queue calling back into javascript
    // and creating a few js-objects...
    // and more...
    // and more...
    } catch (boost::thread_interrupted &) {
    ATLTRACE(L"Thread interrupted\n");
    }
    }

    As I said: A breakpoint set at the last closing curly brace got hit, but the join() call from the main thread that triggered the thread interruption never finished. After a while (quite a while!) of playing around, debugging (a release version btw, since the problem happened only in a release build) and staring at the code I noticed the neat little line near the top of the thread:

    BOOST_SCOPE_EXIT_ALL(&) { CoUninitialize(); };

    "Wait a sec! What's that?" "BOOST_SCOPE_EXIT_ALL - Maybe this means, it executes some code when the current scope exits? Maybe CoUninitialize()?. And doesn't CoUninitialize() block, when the current thread still holds some COM object references?" So I started to dig into the code of the actual tasks that were executed here, and one of them in deed creates some objects. But since my colleague learned COM from me and I slap his fingers everytime I see a raw pointer somewhere, and also from what I found in the code there should not be a problem. The object was created nicely via

    CComPtr<IDispatch> createJSObjectInstance()
    {
    CComPtr<IDispatchEx> creatorObject = threadMarshaller->get();
    DISPPARAMS params = {0};
    _variant_t result;

    S 1 Reply Last reply
    0
    • I imagiro

      I just spent nearly two days debugging an COM exe server using ATL and boost. There is a boost thread, acting as an asynchronous task manager that gets task queued which do callbacks into COM objects (into JScript objects). The thread was hanging in join(), even though a breakpoint set at the end of the thread function was hit. The code was written by a collegue, who is a god with boost, but rather new to ATL - and he hates it. Me in turn did not use a lot of boost (yet), but with COM/ATL I have quite some experience, and I like it. So first I suspected boost to be somehow buggy, although I could not really imagine that such a widely used thing like boost::thread would have such a serious bug or a somehow screwed functionality. Here is (shortened) how the thread looks:

      void operator()()
      {
      CoInitializeEx(NULL, COINIT_APARTMENTTHREADED);
      BOOST_SCOPE_EXIT_ALL(&) { CoUninitialize(); };
      try {
      // lots of code here...
      // e.g. running a task from a task queue calling back into javascript
      // and creating a few js-objects...
      // and more...
      // and more...
      } catch (boost::thread_interrupted &) {
      ATLTRACE(L"Thread interrupted\n");
      }
      }

      As I said: A breakpoint set at the last closing curly brace got hit, but the join() call from the main thread that triggered the thread interruption never finished. After a while (quite a while!) of playing around, debugging (a release version btw, since the problem happened only in a release build) and staring at the code I noticed the neat little line near the top of the thread:

      BOOST_SCOPE_EXIT_ALL(&) { CoUninitialize(); };

      "Wait a sec! What's that?" "BOOST_SCOPE_EXIT_ALL - Maybe this means, it executes some code when the current scope exits? Maybe CoUninitialize()?. And doesn't CoUninitialize() block, when the current thread still holds some COM object references?" So I started to dig into the code of the actual tasks that were executed here, and one of them in deed creates some objects. But since my colleague learned COM from me and I slap his fingers everytime I see a raw pointer somewhere, and also from what I found in the code there should not be a problem. The object was created nicely via

      CComPtr<IDispatch> createJSObjectInstance()
      {
      CComPtr<IDispatchEx> creatorObject = threadMarshaller->get();
      DISPPARAMS params = {0};
      _variant_t result;

      S Offline
      S Offline
      Super Lloyd
      wrote on last edited by
      #2

      Interesting!! :)

      My programming get away... The Blog... DirectX for WinRT/C# since 2013! Taking over the world since 1371!

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups