Problem with Single Threaded Object VC++ 
Author Message
 Problem with Single Threaded Object VC++

Hi,

I created a DLL with ATL which is supposed to be singled threaded (derived
from CComSingleThreadModel). I did this in order to serialize all the calls
in my ASP pages.

So, I opened to different navigators, I logged in two different sessions,
and I tried to execute my ASP scripts which contains :
Set obj = Server.CreateObject("MyLib.MyInterface")
obj.MyMethod
Set obj = Nothing

The MyMethod method takes a long time to execute.

I loaded the page in my first nav. OK. The component was instanciated and
the method was running (90% CPU used which is normal).

Then I tried to load the page in my other nav (MyMethod still running). And
the problem is that the instanciation worked ! I thought all calls would be
serialized with a single threaded model.

Can someone explain me that ?

Thanks.

Fred



Fri, 29 Apr 2005 01:50:36 GMT  
 Problem with Single Threaded Object VC++
Components running under ASP.dll need to run as STAs which you are. This
means when the request is made by the page to instantiate and run, the calls
are directed to a pool of STAs running under INETINFO. One call went to one
STA, the other to another. Check the thread id from both calls to
verify.However, these calls are serialized per STA. No other request comes
through until the process is done, most of the time. There are situations
where a component executes a long running database queury will have the
message pump checked for that thread.


Quote:
> Hi,

> I created a DLL with ATL which is supposed to be singled threaded (derived
> from CComSingleThreadModel). I did this in order to serialize all the
calls
> in my ASP pages.

> So, I opened to different navigators, I logged in two different sessions,
> and I tried to execute my ASP scripts which contains :
> Set obj = Server.CreateObject("MyLib.MyInterface")
> obj.MyMethod
> Set obj = Nothing

> The MyMethod method takes a long time to execute.

> I loaded the page in my first nav. OK. The component was instanciated and
> the method was running (90% CPU used which is normal).

> Then I tried to load the page in my other nav (MyMethod still running).
And
> the problem is that the instanciation worked ! I thought all calls would
be
> serialized with a single threaded model.

> Can someone explain me that ?

> Thanks.

> Fred



Fri, 29 Apr 2005 02:27:23 GMT  
 Problem with Single Threaded Object VC++
Well... I should have said : how can I avoid this problem (for me) and make
all the instanciations from all the ASP pages serialized ?
Quote:

> Components running under ASP.dll need to run as STAs which you are.
> This means when the request is made by the page to instantiate and
> run, the calls are directed to a pool of STAs running under INETINFO.
> One call went to one STA, the other to another. Check the thread id
> from both calls to verify.However, these calls are serialized per
> STA. No other request comes through until the process is done, most
> of the time. There are situations where a component executes a long
> running database queury will have the message pump checked for that
> thread.



>> Hi,

>> I created a DLL with ATL which is supposed to be singled threaded
>> (derived from CComSingleThreadModel). I did this in order to
>> serialize all the
> calls
>> in my ASP pages.

>> So, I opened to different navigators, I logged in two different
>> sessions, and I tried to execute my ASP scripts which contains :
>> Set obj = Server.CreateObject("MyLib.MyInterface")
>> obj.MyMethod
>> Set obj = Nothing

>> The MyMethod method takes a long time to execute.

>> I loaded the page in my first nav. OK. The component was
>> instanciated and the method was running (90% CPU used which is
>> normal).

>> Then I tried to load the page in my other nav (MyMethod still
>> running).
> And
>> the problem is that the instanciation worked ! I thought all calls
>> would
> be
>> serialized with a single threaded model.

>> Can someone explain me that ?

>> Thanks.

>> Fred



Fri, 29 Apr 2005 02:38:54 GMT  
 Problem with Single Threaded Object VC++
Not sure why you want to do that. What about scaleability? You can run as
Single Thread (not Single Thread Apartment) and all objects and calls are
serialized under a single thread (Primary STA). Easy to setup under VB not
sure about VC++/ATL.


Quote:
> Well... I should have said : how can I avoid this problem (for me) and
make
> all the instanciations from all the ASP pages serialized ?


> > Components running under ASP.dll need to run as STAs which you are.
> > This means when the request is made by the page to instantiate and
> > run, the calls are directed to a pool of STAs running under INETINFO.
> > One call went to one STA, the other to another. Check the thread id
> > from both calls to verify.However, these calls are serialized per
> > STA. No other request comes through until the process is done, most
> > of the time. There are situations where a component executes a long
> > running database queury will have the message pump checked for that
> > thread.



> >> Hi,

> >> I created a DLL with ATL which is supposed to be singled threaded
> >> (derived from CComSingleThreadModel). I did this in order to
> >> serialize all the
> > calls
> >> in my ASP pages.

> >> So, I opened to different navigators, I logged in two different
> >> sessions, and I tried to execute my ASP scripts which contains :
> >> Set obj = Server.CreateObject("MyLib.MyInterface")
> >> obj.MyMethod
> >> Set obj = Nothing

> >> The MyMethod method takes a long time to execute.

> >> I loaded the page in my first nav. OK. The component was
> >> instanciated and the method was running (90% CPU used which is
> >> normal).

> >> Then I tried to load the page in my other nav (MyMethod still
> >> running).
> > And
> >> the problem is that the instanciation worked ! I thought all calls
> >> would
> > be
> >> serialized with a single threaded model.

> >> Can someone explain me that ?

> >> Thanks.

> >> Fred



Fri, 29 Apr 2005 03:33:40 GMT  
 Problem with Single Threaded Object VC++


Fri, 19 Jun 1992 00:00:00 GMT  
 Problem with Single Threaded Object VC++
Have a look at the Application server variable. You can use that to set up
one ATL object that is common across all sessions. Is that what you want?

Again, why does this need to be serialized? Usually the goal is to design
your ATL class to serve up objects for multiple clients simultaneously.



Fri, 29 Apr 2005 04:17:04 GMT  
 Problem with Single Threaded Object VC++
The basic question is, why do you want to serialize if your method takes a
very long time to execute? You are killing scalability.


Fri, 29 Apr 2005 04:13:30 GMT  
 Problem with Single Threaded Object VC++


Fri, 19 Jun 1992 00:00:00 GMT  
 Problem with Single Threaded Object VC++
With ATL, you've got 4 possibilities for the threading model : single,
apartment, both and free.
I choosed single, not apartement as you thought. Now you can understand my
problem...
Quote:

> Not sure why you want to do that. What about scaleability? You can
> run as Single Thread (not Single Thread Apartment) and all objects
> and calls are serialized under a single thread (Primary STA). Easy to
> setup under VB not sure about VC++/ATL.



Fri, 29 Apr 2005 04:16:50 GMT  
 Problem with Single Threaded Object VC++


Fri, 19 Jun 1992 00:00:00 GMT  
 Problem with Single Threaded Object VC++

Quote:
> Again, why does this need to be serialized? Usually the goal is to
> design your ATL class to serve up objects for multiple clients
> simultaneously.

The point is not if I need to serialize the calls or not, but how. I've got
good reasons to do so (would be too long to expose). My question is why my
calls aren't  serialized with the single thread model
(CComSingleThreadModel) ? If this behaviour is normal (I don't think so),
what can I do ?


Fri, 29 Apr 2005 04:26:10 GMT  
 Problem with Single Threaded Object VC++
What determines the apartment your ATL object joins, is not whether or not
you are using CComSingleThreadModel, but what is marked in the registry.

Check your XXXX.rgs file. I suspect you will see a line such as:

    val ThreadingModel = s 'Apartment'

If so, your ATL object is marked to join an STA.

By design INETINFO is smart enough to keep a pool of these STA's running.
This way, the ASP interpeter can spin up a server object that is marked as
STA, in spite of the fact that some other client has already acquired its
own server object that is running in a different apartment.

There are a number of ways of tackling this. It is difficult to recommend
the best solution, because you seem hesitant about describing your overall
design goals. Do you want singleton behaviour? Do you want to have a
background thread managing a single resource, but have multiple objects
access this resource?

So I can only talk in generalities.

You could, for example, manage serialization yourself. This can be done
using any of the standard synchronization objects available to you, such as
critical sections and mutexes.

Or you could use the Application object I described in my previous posting.
This would allow you to create ONE ATL object across all sessions. But I
don't know if the design of your code would allow for this.

HTH,

Brian Muth



Fri, 29 Apr 2005 05:22:58 GMT  
 Problem with Single Threaded Object VC++

Quote:

> > Again, why does this need to be serialized? Usually the goal is to
> > design your ATL class to serve up objects for multiple clients
> > simultaneously.

> The point is not if I need to serialize the calls or not, but how. I've got
> good reasons to do so (would be too long to expose). My question is why my
> calls aren't  serialized with the single thread model
> (CComSingleThreadModel) ? If this behaviour is normal (I don't think so),
> what can I do ?

It's easy to serialize calls within a single ASP Application:
Application.Lock
call goes here...
Application.Unlock
...

No muss, no fuss, no C++!-))



Fri, 29 Apr 2005 05:28:46 GMT  
 Problem with Single Threaded Object VC++

Quote:
> It's easy to serialize calls within a single ASP Application:
> Application.Lock
> call goes here...
> Application.Unlock
> ...

> No muss, no fuss, no C++!-))

Could have been a good idea, but it doesn't work at all !!! This is a very
dangerous method !
I said my component was heavy time consuming. It can take up to 4 or 5
minutes to execute. By this time, no other ASP pages which need an
application object or variable can run !


Fri, 29 Apr 2005 05:36:41 GMT  
 Problem with Single Threaded Object VC++
You say you want the ATL object to serialize across all instances, but you
don't want to hold up other ASP pages. One goal is not compatible with the
other.

I'm sure there is a more reasonable approach if you describe your design
requirements.



Fri, 29 Apr 2005 05:47:24 GMT  
 
 [ 21 post ]  Go to page: [1] [2]

 Relevant Pages 

1. Single Thread MTS Object?

2. How do I create Apartment-threaded objects from a Both-threaded object

3. Single Thread VS. Multi Thread

4. Free threaded outof proc server and Single threaded components

5. Multiple Threads thru` single thread

6. libraries built single threaded in a multi-threaded project

7. Problem with scripting context when using VB com object inside VC com object

8. vc++ thread problem

9. Single line of code crashes VC 5 but not VC 4.x

10. Single line of code crashes VC 5 but not VC 4.x

11. Thread blocking problem with COINIT_APARTMENTTHREADED object

12. Threading problem in ATL COM object

 

 
Powered by phpBB® Forum Software