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. Creating a new thread from within an MTA

Creating a new thread from within an MTA

Scheduled Pinned Locked Moved COM
comgraphicsdesignarchitecturehelp
4 Posts 3 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.
  • J Offline
    J Offline
    Jeremy Pullicino
    wrote on last edited by
    #1

    I am designing a module and I want to know if this is a good design or not. My conerns are that I will be conflicting with the COM threading architecture. Could anyone tell me if this is ok? : I have an object, IQueue which has a method IQueue::Add([in] long nID) IQueue is an MTA, meaning that its methods could be called multiple times simaltaneusly. long nID will be added to a vector. Adding to the vector is thread safe. (using my own protection mechanism) Till there I am fine. Now, here is where I need help. When IQueue is initialized, I want to create a thread that will scan this vector, pick up the longs from it and do something with them. Is it OK if I create a new thread from within IQueue? (this new thread will only be accessible internally from IQueue) :eek: Any thoughts? Thanks! Jeremy. "Hey man, Taliban, Tali me Banana."

    S L 2 Replies Last reply
    0
    • J Jeremy Pullicino

      I am designing a module and I want to know if this is a good design or not. My conerns are that I will be conflicting with the COM threading architecture. Could anyone tell me if this is ok? : I have an object, IQueue which has a method IQueue::Add([in] long nID) IQueue is an MTA, meaning that its methods could be called multiple times simaltaneusly. long nID will be added to a vector. Adding to the vector is thread safe. (using my own protection mechanism) Till there I am fine. Now, here is where I need help. When IQueue is initialized, I want to create a thread that will scan this vector, pick up the longs from it and do something with them. Is it OK if I create a new thread from within IQueue? (this new thread will only be accessible internally from IQueue) :eek: Any thoughts? Thanks! Jeremy. "Hey man, Taliban, Tali me Banana."

      S Offline
      S Offline
      Shadi Al Kahwaji
      wrote on last edited by
      #2

      Hi, There are two things (as I saw from what you have said) that you have to care of: 1- Once you have created a new thread (withing an MTA or STA), this new thread does not know anything about COM Runtime Environment, this means that you have to call CoInitialize(0) or CoInitializeEx(0, ..). 2- Also this new thread cannot access your Vector, you have to pass this vector to the new thread. This is what I can say about your problem :) Enjoy, ShadiK. Shadi Al-Kahwaji

      J 1 Reply Last reply
      0
      • S Shadi Al Kahwaji

        Hi, There are two things (as I saw from what you have said) that you have to care of: 1- Once you have created a new thread (withing an MTA or STA), this new thread does not know anything about COM Runtime Environment, this means that you have to call CoInitialize(0) or CoInitializeEx(0, ..). 2- Also this new thread cannot access your Vector, you have to pass this vector to the new thread. This is what I can say about your problem :) Enjoy, ShadiK. Shadi Al-Kahwaji

        J Offline
        J Offline
        Jeremy Pullicino
        wrote on last edited by
        #3
        1. Ok, no problem. Thanks for pointing it out. 2) No problem there, I have a mechanism to do that. Thanks! Jeremy. "Hey man, Taliban, Tali me Banana."
        1 Reply Last reply
        0
        • J Jeremy Pullicino

          I am designing a module and I want to know if this is a good design or not. My conerns are that I will be conflicting with the COM threading architecture. Could anyone tell me if this is ok? : I have an object, IQueue which has a method IQueue::Add([in] long nID) IQueue is an MTA, meaning that its methods could be called multiple times simaltaneusly. long nID will be added to a vector. Adding to the vector is thread safe. (using my own protection mechanism) Till there I am fine. Now, here is where I need help. When IQueue is initialized, I want to create a thread that will scan this vector, pick up the longs from it and do something with them. Is it OK if I create a new thread from within IQueue? (this new thread will only be accessible internally from IQueue) :eek: Any thoughts? Thanks! Jeremy. "Hey man, Taliban, Tali me Banana."

          L Offline
          L Offline
          Lost User
          wrote on last edited by
          #4

          This is a real nitpicker's comment... But "IQueue is an MTA" is not a valid statement. IQueue is an interface, and it can be implemented by many different COM objects. Each of these objects will have their own threading model. I assume what you mean is "I have an object with an IQueue interface, and the object's threading model is MTA." :) As for your question, what you are doing is a-OK, just make sure you do indeed specify the object as free-threaded. The first time something similar to what you are doing here, I had specified in the ATL wizard "Both" - and so when the object was instantiated by an object in an STA evil things began to occur :).

          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