|
-
February 24th, 2011, 03:33 PM
#16
Re: Enforcing single thread in MFC ActiveX using Mutex
I need multiple instances of the engine.
-
February 24th, 2011, 03:47 PM
#17
Re: Enforcing single thread in MFC ActiveX using Mutex
 Originally Posted by Dawoodoz
I need multiple instances of the engine.
If the engine itself isn't thread safe, then you aren't going to be able to use multiple instances of it from different threads within the same process. That's it - end of story.
What you can do is to wrap the engine inside an out of proc COM server (.exe server) and configure the COM server to create a new process for each engine instance.
Then have your ActiveX control create an instance of the engine via the COM server as appropriate. Not real efficient, but doable.
Of course, a better approach would be to make the engine threadsafe.
-
February 24th, 2011, 03:50 PM
#18
Re: Enforcing single thread in MFC ActiveX using Mutex
 Originally Posted by Arjay
If the engine itself isn't thread safe, then you aren't going to be able to use multiple instances of it within the same process.
I have done that and it is safe when the instances don't have any memory in common. The problem with thread safety occur when the user make two calls to the same instance.
-
February 24th, 2011, 05:04 PM
#19
Re: Enforcing single thread in MFC ActiveX using Mutex
 Originally Posted by Dawoodoz
I have done that and it is safe when the instances don't have any memory in common. The problem with thread safety occur when the user make two calls to the same instance.
You have done what? If multiple instances of the engine don't work 100% of the time, then the engine isn't thread safe. If the 'memory in common' isn't within the engine, then synchronize access to the memory.
Btw, in addition to accessing the engine with the COM class instance, are you accessing any global variables?
-
February 24th, 2011, 05:09 PM
#20
Re: Enforcing single thread in MFC ActiveX using Mutex
Multiple instances of the engine do work 100% of the time as long as the user don't make 2 calls to the same instance. I use ActiveX with no data outside of the class since sharing data between them would be stupid.
-
February 24th, 2011, 05:33 PM
#21
Re: Enforcing single thread in MFC ActiveX using Mutex
So separate instances of the engine work okay, but each engine instance isn't thread safe. Okay, that brings the question:
When do you create an engine instance? Do you create a new engine for each instance of CDFPGECtrl?
-
February 24th, 2011, 05:34 PM
#22
Re: Enforcing single thread in MFC ActiveX using Mutex
The engine is created when the control is created but a starting call is needed before the engine is running and accepting input.
-
February 24th, 2011, 06:14 PM
#23
Re: Enforcing single thread in MFC ActiveX using Mutex
 Originally Posted by Dawoodoz
The engine is created when the control is created but a starting call is needed before the engine is running and accepting input.
So when a control is created it creates a new engine instance? I'm asking because your term 'the engine' may imply only one engine instance (shared between multiple control instances).
-
February 25th, 2011, 05:06 AM
#24
Re: Enforcing single thread in MFC ActiveX using Mutex
Yes, they share absolutely nothing like a regular ActiveX component.
-
February 25th, 2011, 07:14 AM
#25
Re: Enforcing single thread in MFC ActiveX using Mutex
Put some TRACE statements in your code and spew the output to a debug window. In the TRACE statement, record the method name and the thread Id of the current thread.
That will give you an idea of if things are working as you expect. From what you are describing it sounds like an ActiveX control instance is getting shared between threads.
-
February 25th, 2011, 07:16 AM
#26
Re: Enforcing single thread in MFC ActiveX using Mutex
Yes, that is what I try to protect it from because my engine should be foolproof for beginners.
-
February 25th, 2011, 11:57 AM
#27
Re: Enforcing single thread in MFC ActiveX using Mutex
 Originally Posted by Dawoodoz
Yes, that is what I try to protect it from because my engine should be foolproof for beginners.
What could help is if you returned rich error information from your COM methods.
Why not use the COM approach and return an HRESULT
Code:
HRESULT CDFPGECtrl::Camera_RenderScene(...);
-
February 25th, 2011, 12:03 PM
#28
Re: Enforcing single thread in MFC ActiveX using Mutex
 Originally Posted by Arjay
What could help is if you returned rich error information from your COM methods.
Why not use the COM approach and return an HRESULT
Code:
HRESULT CDFPGECtrl::Camera_RenderScene(...);
Checking for return values all the time makes the engine less user friendly and I can't have multiple return values. I have a delayed message system that puts a message in a queue when an error occurs so that it is threadsafe for Visual Basic 6 but not any multicore language.
-
February 25th, 2011, 04:40 PM
#29
Re: Enforcing single thread in MFC ActiveX using Mutex
Why not do both? Provide return values for those developers that want to use them and give the option of the error messaging.
Experience developers probably want to know that a call has succeeded or not at the time of making the call.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|