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. General Programming
  3. COM
  4. IScriptControlPtr bad multithreaded behaviour?

IScriptControlPtr bad multithreaded behaviour?

Scheduled Pinned Locked Moved COM
c++questionannouncement
5 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.
  • H Offline
    H Offline
    humps
    wrote on last edited by
    #1

    I have a VC++ program in which two IScriptControlPtr smart pointers are created in thread "1". Thread "2" calls the Run() method against the first IScriptControlPtr, and thread "3" calls the Run() method against the second one. All three threads call CoInitializeEx(NULL,COINIT_MULTITHREADED) first. What I am finding is, thread 2 (or 3) blocks until thread 3 (or 2) has finished, even though they are running against separate IScriptControlPtr objects (and no other thread is trying to access these smart pointers). Has anyone seen this behaviour before / is this to be expected? Is there perhaps bad multithreaded handling in msscript.ocx? (I am using version 1.0.0.7615). Many thanks, Neil.

    M 1 Reply Last reply
    0
    • H humps

      I have a VC++ program in which two IScriptControlPtr smart pointers are created in thread "1". Thread "2" calls the Run() method against the first IScriptControlPtr, and thread "3" calls the Run() method against the second one. All three threads call CoInitializeEx(NULL,COINIT_MULTITHREADED) first. What I am finding is, thread 2 (or 3) blocks until thread 3 (or 2) has finished, even though they are running against separate IScriptControlPtr objects (and no other thread is trying to access these smart pointers). Has anyone seen this behaviour before / is this to be expected? Is there perhaps bad multithreaded handling in msscript.ocx? (I am using version 1.0.0.7615). Many thanks, Neil.

      M Offline
      M Offline
      Mike Dimmick
      wrote on last edited by
      #2

      The msscript.ocx control is registered with the Apartment threading model. This means it has affinity with the thread on which it is created - COM will force calls from a different thread onto the thread which created the object. If you want to use multiple script controls concurrently, you should create them on the threads which will call their methods. I'm not sure, but I think using COINIT_MULTITHREADED with an Apartment object will cause you to get a proxy to the object even though you're calling an object on the same thread. Stability. What an interesting concept. -- Chris Maunder

      H 1 Reply Last reply
      0
      • M Mike Dimmick

        The msscript.ocx control is registered with the Apartment threading model. This means it has affinity with the thread on which it is created - COM will force calls from a different thread onto the thread which created the object. If you want to use multiple script controls concurrently, you should create them on the threads which will call their methods. I'm not sure, but I think using COINIT_MULTITHREADED with an Apartment object will cause you to get a proxy to the object even though you're calling an object on the same thread. Stability. What an interesting concept. -- Chris Maunder

        H Offline
        H Offline
        humps
        wrote on last edited by
        #3

        Thanks for your reply, Mike. I suspected this might be the case. When you say "The msscript.ocx control is registered with the Apartment threading model" ... is this documented somewhere on the web? I spent some time searching, but don't recall that particular chestnut :-( It might be nice to have some definitive documentation for once, rather then relying on Google and trial and error!!!!

        M 1 Reply Last reply
        0
        • H humps

          Thanks for your reply, Mike. I suspected this might be the case. When you say "The msscript.ocx control is registered with the Apartment threading model" ... is this documented somewhere on the web? I spent some time searching, but don't recall that particular chestnut :-( It might be nice to have some definitive documentation for once, rather then relying on Google and trial and error!!!!

          M Offline
          M Offline
          Mike Dimmick
          wrote on last edited by
          #4

          It's not documented on the web AFAIK, but ActiveX controls are almost always registered with the Apartment threading model (although you'll see some not marked at all, therefore running on the primary thread, and some marked Both). An ActiveX control (as opposed to a component) is intended for use on a window. As for how msscript.ocx is registered, I used regedit and searched HKEY_CLASSES_ROOT\CLSID for that filename. I never asked why you're not just using the script engines directly. This page[^] suggests which you should use when. Stability. What an interesting concept. -- Chris Maunder

          H 1 Reply Last reply
          0
          • M Mike Dimmick

            It's not documented on the web AFAIK, but ActiveX controls are almost always registered with the Apartment threading model (although you'll see some not marked at all, therefore running on the primary thread, and some marked Both). An ActiveX control (as opposed to a component) is intended for use on a window. As for how msscript.ocx is registered, I used regedit and searched HKEY_CLASSES_ROOT\CLSID for that filename. I never asked why you're not just using the script engines directly. This page[^] suggests which you should use when. Stability. What an interesting concept. -- Chris Maunder

            H Offline
            H Offline
            humps
            wrote on last edited by
            #5

            The reason I didn't use the script engines directly is - I didn't know about them! I am just a beginner with this to be honest. Thanks for bringing it to my attention, it definitely looks like the way to go. cheers, Neil

            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