|
Neohapsis is currently accepting applications for employment. For more information, please visit our website www.neohapsis.com or email hr@neohapsis.com |
From: Syed Alam (Volt) (a-salam
MICROSOFT.COM)Date: Thu Sep 20 2001 - 16:21:23 CDT
I remember that there is a Win32 API to find out if a Windows Dispatched
call is in being process. You can use it to find out if u r serving a
Windows message within another Windows message call.
Is there any equivalent function in COM for that? Or for STA, we can use
the above-mentioned call? What is that API, by the way?
-Syed
-----Original Message-----
From: Steve Johnson [mailto:sjohnson
3TSYSTEMS.COM]
Sent: Thursday, September 20, 2001 10:23 AM
To: DCOM
DISCUSS.MICROSOFT.COM
Subject: Re: Out of process singleton
Yes, I am sure that a STA can be reentered. When a COM call leaves the
apartment, the thread of execution (causality) leaves the STA thread.
This
leaves the STA available to process incoming calls.
Kernel synchronization objects are useless to solve this problem. The
reason is that they work on the principle of thread affinity. This
ensures
that only one thread owns the object at any given time. This is useless
in
your situation because the STA executes all incoming calls on its one
thread.
Illustration:
1 - One client calls Method1
2 - In Method1, the object enters CriticalSection1, which now belongs to
the
STA thread.
3 - Method1 makes a COM call outside the apartment, leaving the STA free
to
process incoming calls.
4 - Second client calls Method1
5 - Method1 enters CriticalSection1 happily, because the STA thread
already
owns CriticalSection1 from the previous call.
As you can see, this provides no protection.
One suggestion to solve this would be to have a member boolean, say,
m_bLock. Then you simply check the value of m_bLock to determine
whether
execution is allowed. If you need further protection, you can use the
InterlockedX family of APIs to set and reset the boolean.
Illustration:
1 - Method1 is called
2 - Check that m_bLock is FALSE
3 - Set m_bLock to TRUE
4 - Make outgoing COM calls
5 - Method1 is called by another client
6 - m_bLock is TRUE, so reject the call.
Others on the list may have much better ideas as I've never had to solve
this problem myself.
Steve Johnson
3t Systems
mailto://sjohnson
3tsystems.com
(303) 858-8800 x265
> Are you sure about that Steve? Surely the whole point of a
> Single Threaded
> Apartment is that the (in this case single) object instance can only
be
> entered once and has to complete before the next function call to
> it can be
> serviced?
>
>
> If you are sure, How can I mutex this object's method so that it acts
in a
> single threaded fashion when I need it to without causing deadlocks.
All
> the methods I did try for this (Critical Section, Mutex, Windows
Message
> with AtlWaitWithMessageLoop) caused deadlocking.
----------------------------------------------------------------
Users Guide http://discuss.microsoft.com/archives/mailfaq.asp
contains important info. Save time, search the archives at
http://discuss.microsoft.com/archives/index.html .
To unsubscribe, mailto:DCOM-signoff-request
DISCUSS.MICROSOFT.COM
----------------------------------------------------------------
Users Guide http://discuss.microsoft.com/archives/mailfaq.asp
contains important info. Save time, search the archives at
http://discuss.microsoft.com/archives/index.html .
To unsubscribe, mailto:DCOM-signoff-request
DISCUSS.MICROSOFT.COM
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]