Threading models issues 
Author Message
 Threading models issues

Hi

Can someone suggest me some really helpful links..I want to run multiple
threads in one apramtment. How to do this..
I want to make a process free threaded... A COM object (thread safe) will be
accessed. This object holds some references to other objects.. Whenever the
COM Object receive a method call; is this call received in different thread
and all the references that this object is holding have to be marshed in
different methods that might be called in some method.. getting my point...
let me know what u think of it..

regards

asim hussnain



Mon, 28 Feb 2005 18:42:44 GMT  
 Threading models issues
Quote:

> Hi

> Can someone suggest me some really helpful links..I want to run
> multiple threads in one apramtment.

This is not advisable.
Better run the multiple threads in the main thread apartment, not in one of
the already pooled threads from one apartment, if you'll do, you break the
COM rules and possible, it would work by synchronizing and custom marshaling
but it's not safe.

Quote:

> regards

> asim hussnain

--


Mon, 28 Feb 2005 18:22:45 GMT  
 Threading models issues
Have your threads enter multithreaded apartment (MTA). It is called
"multithreaded" for a reason - there is only one MTA per process, all
threads entering MTA belong to the same apartment, no marshaling is
necessary when transferring interface pointers between MTA threads.
Looks like that's exactly what you want.
--
With best wishes,
    Igor Tandetnik

"For every complex problem, there is a solution that is simple, neat,
and wrong." H.L. Mencken


Quote:
> Hi

> Can someone suggest me some really helpful links..I want to run
multiple
> threads in one apramtment. How to do this..
> I want to make a process free threaded... A COM object (thread safe)
will be
> accessed. This object holds some references to other objects..
Whenever the
> COM Object receive a method call; is this call received in different
thread
> and all the references that this object is holding have to be marshed
in
> different methods that might be called in some method.. getting my
point...
> let me know what u think of it..

> regards

> asim hussnain



Mon, 28 Feb 2005 23:38:15 GMT  
 Threading models issues


Quote:

> > Can someone suggest me some really helpful links..I want to run
> > multiple threads in one apramtment.
> This is not advisable.

Huh? Ever heard of multithreaded apartment (MTA)?

Quote:
> Better run the multiple threads in the main thread apartment, not in
one of
> the already pooled threads from one apartment

How is that different from running multiple threads in one apartment,
which, according to you, is not advisable? What exactly is "already
pooled thread"?

Quote:
> if you'll do, you break the
> COM rules and possible, it would work by synchronizing and custom
marshaling
> but it's not safe.

If you do what?

--
With best wishes,
    Igor Tandetnik

"For every complex problem, there is a solution that is simple, neat,
and wrong." H.L. Mencken



Mon, 28 Feb 2005 23:42:14 GMT  
 Threading models issues
Quote:




>>> Can someone suggest me some really helpful links..I want to run
>>> multiple threads in one apramtment.
>> This is not advisable.

> Huh? Ever heard of multithreaded apartment (MTA)?

Of course, but I understood that he was talking about STA and from there on,
working with multiple threads, because he said, multiple threads in *one*
apartment.
If I totally misunderstood this question, then *oops*...


Tue, 01 Mar 2005 01:15:20 GMT  
 Threading models issues


Quote:




> >>> Can someone suggest me some really helpful links..I want to run
> >>> multiple threads in one apramtment.
> >> This is not advisable.

> > Huh? Ever heard of multithreaded apartment (MTA)?

> Of course, but I understood that he was talking about STA and from
there on,
> working with multiple threads, because he said, multiple threads in
*one*
> apartment.
> If I totally misunderstood this question, then *oops*...

Well, STA stands for "single-threaded apartment", precisely because
there can only ever be one thread belonging to such an apartment.
"Multiple threads in *one* apartment" can only mean MTA, by definition.
I don't see any way this can be misinterpreted, though of course
Murphy's law says it will anyway.
--
With best wishes,
    Igor Tandetnik

"For every complex problem, there is a solution that is simple, neat,
and wrong." H.L. Mencken



Tue, 01 Mar 2005 03:25:58 GMT  
 Threading models issues
Thank you all for all the help... However my problem is not solved yet.

I've  a free threaded component (actually its VBS engine). I wrote a
out-of-proc atl exe host application to use this component. Before I pass
IActiveScript interface to VBS, vbs behaves like a free threaded component
and can be used in any thread without marshaling. Once I supply vbs with the
IActiveScript Interface through SetScriptSite(), VBS develops affinity with
the thread calling the SetScriptSite and rejects any other request that
might be coming from any other thread.

Situation ONE: my atl exe host app calls CoInitialize(NULL) and then sets
the VBS::SetScriptSite and then spawns a thread. Passes the thread a Stream
that contains the marshalled interface pointer of VBS. This pointer can be
used in the thread.

Situation TWO: my atl exe host app calls CoInitialize(MULTITHREADED) and
then sets the VBS::SetScriptSite and then spawns a thread. Passes the thread
a Stream that contains the marshalled interface pointer of VBS. This
pointer, though its marshalled, can 't be used in some other thread...its
found invalid.

I want to avoid marshalling. But this developed thread affinity is a problem
. And using the pointer across thread is not possible even when marshaling
is done (in case of Free threaded host)

Can someone suggest me a way around or some other technique so that I could
use the VBS* in any thread without having to marshal all the calls across
threads.

Regards

Asim Hussnain



Tue, 01 Mar 2005 18:15:10 GMT  
 
 [ 7 post ] 

 Relevant Pages 

1. what threading model is default when no Threading model key

2. Threading Model / Marshalling issue

3. COM Threading Model for ISAPI Worker Threads

4. Exe server threading model - events from worker thread question

5. DLL issue: Problem with beginning a new thread when one thread gets into an infinite loop

6. Threading Models

7. Changin Threading model causing serious problems

8. OLE/COM Viewer: Inproc Handler Tab Option->Threading Model (Question)

9. Threading models confusion

10. question about the threading model

11. Threading model clarification wanted.

12. VC++ 7 /ATL 7 server threading model

 

 
Powered by phpBB® Forum Software