OSEC

Neohapsis is currently accepting applications for employment. For more information, please visit our website www.neohapsis.com or email hr@neohapsis.com
 
From: Alex Smith (asmithMATRA.CO.UK)
Date: Thu Sep 20 2001 - 07:55:22 CDT

  • Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]

    Thanks Andrew - Perhaps I have worded this badly.

    I understand that all clients will get the same instance back (and that is
    indeed what seems to be happening), the problem is that calls into this
    object seem not to be synchronized and so I see the
    CMyObjectWithAProblem::myOnlyMethod method being called by both clients and
    the first call does not complete before the second one starts, so my object
    gets initialised twice (which breaks it).

    So I was wondering why the calls are being dealt with at the same time given
    that the object is created by apartment initialised threads..

    The 2 clients in this example are the service that was written in the same
    VC6 project as the singleton object and another service.

    Cheers.
    _________
    Alex Smith

    -----Original Message-----
    From: Andrew Bolstridge [mailto:Andrew.BolstridgeAIT.CO.UK]
    Sent: 20 September 2001 13:39
    To: DCOMDISCUSS.MICROSOFT.COM
    Subject: Re: Out of process singleton

    It sounds perfectly normal, though you make it sound as if you have 1 client
    calling the object in one paragraph, but 2 in a later para.

    A singleton object means you have 1 instance created. no matter how many
    clients 'create' this object, they actually get back this single instance.

    When more than 1 client calls methods on that, then the calls are
    synchronised (ie only 1 client will ever call a method at any given time),
    but this does not prevent additional clients from calling the object.

    Andy.

    -----Original Message-----
    From: Alex Smith [mailto:asmithMATRA.CO.UK]
    Sent: 20 September 2001 13:08
    To: DCOMDISCUSS.MICROSOFT.COM
    Subject: Out of process singleton

    Hi,

    I have a COM Service, when it starts up, it starts a thread that creates a
    COM object implemented within the same VC6 project. The COM object has the
    ATL macro:
    DECLARE_CLASSFACTORY_SINGLETON(CMyObjectWithAProblem) to define it as a
    singleton.

    The thread that creates this object begins with:
    CoInitializeEx(NULL, COINIT_APARTMENTTHREADED ), so the created object is
    running in a single threaded apartment.

    The thread calls into this object through it's only exposed method which
    effectively does this:
    HRESULT CMyObjectWithAProblem::myOnlyMethod()
    {
       if (!m_bInitialised)
       {
          Initialise(); /* Which will set the member m_bInitialised to TRUE on
    success and will prevent multiple initialise calls */
       }

       DoTheRealWork();
    }

    The above all runs just fine except...

    I have another service that has the first service as a dependency. When it
    starts, it calls CoInitialize(NULL); then creates the out of process object
    running in the first service and also calls myOnlyMethod() on it. I would
    expect this call to be queued by COM until the other call(s) to the object
    have finished, however, I see the calls being somewhat interwoven and
    initialisation happens twice on the object in the first service. Anyone
    have an explanation?

    Further Info:
    I have traced out the calls to myOnlyMethod() and, as I say, they are
    interwoven. The trace I put in also showed that these calls were to the
    object running in the same processID and threadID and the "this" pointer was
    the same for both calls.

    To try to get round this behaviour, that I see as incorrect, I tried using
    CriticalSections (that didn't work as the calls were executed in the same
    thread which can lock the same CriticalSection any number of times) and I
    tried using Windows Events with AtlWaitWithMessageLoop to control entry.
    This lead to deadlocks for some reason and now I'm stumped.

    Thanks for any help you can give.
    _________
    Alex Smith

    Project Manager
    MATRA Systems (UK) Ltd <http://www.matra.co.uk>
    Registered in Cardiff 2642797
    Tel:+44 (0)2380 684 700 / Fax:+44 (0)2380 619 828
    The content of this email is subject to MATRA's standard company disclaimers
    which can be found at: http://www.matra.co.uk/EmailDisclaimer.html

    ----------------------------------------------------------------
    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-requestDISCUSS.MICROSOFT.COM

    _____________________________________________________________________
    This message has been checked for all known viruses by Star Internet
    delivered through the MessageLabs Virus Scanning Service. For further
    information visit http://www.star.net.uk/stats.asp or alternatively call
    Star Internet for details on the Virus Scanning Service.

    ********************************************************
    Attachments in this message have been swept
    by NAIs TVD (version 4.0.4161) for the presence
    of known computer viruses.
    ********************************************************

    _____________________________________________________________________
    This message has been checked for all known viruses by Star Internet
    delivered through the MessageLabs Virus Scanning Service. For further
    information visit http://www.star.net.uk/stats.asp or alternatively call
    Star Internet for details on the Virus Scanning Service.

    ----------------------------------------------------------------
    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-requestDISCUSS.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-requestDISCUSS.MICROSOFT.COM