Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 17 Jul 2002 23:12:07 -0700
From:      Terry Lambert <tlambert2@mindspring.com>
To:        Jordan DeLong <fracture@allusion.net>
Cc:        freebsd-chat@FreeBSD.ORG
Subject:   Re: Linker sets portability
Message-ID:  <3D365C37.ED032A35@mindspring.com>
References:  <20020717014008.Y99892-100000@valu.uninet.ee> <3D34AC52.2D882455@mindspring.com> <20020717005629.GA42607@allusion.net> <3D34DD99.11FF8526@mindspring.com> <20020717042724.GA45349@allusion.net> <3D3507A1.A166072D@mindspring.com> <20020717211028.GA49636@allusion.net>

next in thread | previous in thread | raw e-mail | index | archive | help
Jordan DeLong wrote:
> > You're really mixing programming models here; you need to decide
> > if you are protecting code, or protecting data -- *one* or the
> > *other* -- and then stick with it, instead of bouncing off the
> > walls.
> 
> Ahh, this is quite possible.  I'll have to look into strategies
> for not recursing on mutexes and such (all the MT coding i've
> done in the past has (possibly incorrectly) assumed this was
> O.K. practice).

The entire idea of protecting data objects over function call
boundaries is really, really broken (unless those calls are
"lock" and "unlock" 8-)).  If you are going to potect data, it
should only be while accessing contents over a short period
of time.

Effectively, this means that for recursive locks to be needed,
you must have figured out some magic way to recurse without
making a function call.  8-).


> > > Certainly, regardless of whether or not recursing on mutexes is
> > > kosher, the creation of a new thread for each method call across
> > > the appartments is quite lame.
> >
> > It's not really necessary, either.  In the sample code that comes
> > with their SDK, e.g. the POP3 server, Microsoft creates a pool of
> > threads, rather than creating and destroying one per call.  I
> > really don't know who programs like you are suggesting.
> 
> The MS rpc stuff.  They could be pooling but not showing the nonactive
> threads in the debugger of course... Dunno.

The RPC code is broken.  Alfred Perlstein has a method of
making RPC calls asynchronous using setjmp/longjmp threads
which he came up with ("zbthreads").  This is also broken;
it basically is an attempt to salvage unsalvageable code for
reuse, when, overall, it would in fact be less time consuming
to rewrite the code from scratch to permit asynchronus calls.


> > > Furthermore, in reality it is quite rare to use com without knowing
> > > if something is in a different adress space, or even a different
> > > threading model.
> >
> > This is practice; it wasn't intended by design.  One problem is
> 
> This is mostly because it was poorly designed.

I think it's because it's poorly used.  You don't blame the
design of the tool when a tool is misused.  We're a very long
way from being able to design a gun that can only be fired by
its owner, and which will refuse to fire, for example, unless
the path of the bullet, including riccochets, will not intersect
the body of the owner.  It's impossible to child-proof everything.

> > > Rental model threading was never implemented by MS.  In win2k they
> > > released a new "neutral appartment", which is similar to the old
> > > RTA idea, but differs in some significant ways.
> >
> > Such as?
> 
> More than one thread can enter it at a time.  The similarity to the
> old RTA idea is that the NTA doesn't own its own threads, it only
> owns components.

Unless you can have more than one thread involved simultaneously,
I don't really see the difference; it sounds like a rule that you
would be following in the rental model case, anyway.

> > You can't force a non-freethreadable module to operate in a mode
> > where freethreading is required.  It will refuse.  It's an attribute
> > you set on the COM object.
> 
> Free threading is about marshalling; it's not something that's
> "attempted" like you seem to think.  When you have a proxied interface
> to an object it *will* do marshalling:  It QI's the object for
> IMarshal and gets back an aggregated object which does the work.
> This object can be the ftm to circumvent marshalling (it implements
> the marshaling stuff by not marshalling), or it can be NULL to tell
> the proxy to use standard marshalling.
> 
> So I still don't follow your eariler comments...  Maybe you are
> talking about something else?

If the interface locks on entry, or queues for handoff to another
thread, it doesn't matter how "freethreaded" the caller thinks it
is, the operation is going to follow the model for the module in
the module.  As long as threading is intended to be allowed, the
relevant model is enforced.

As far as marshalling goes... as I said before, if you are using
in proces servers (I've never actually seen external servers used
when the component was on the same machine as the calling component),
as long as you create the objects prior to creating the threads,
you can freely hand the objects back and forth without marshalling;
this is an artifact of the way Windows handles address spaces.  A
newly created thread gets a copy of the mappings for the objects
that were instantiated in the address space of the program/thread
creating it... it's effectively a copy of the parent address space.
It's very like rfork() with address space sharing.  The difference
is that mappings which are created subsequently to the point the
thread is created are not shared, they are per thread address space
(in other words, TLS is not TL for objects created early enough).

-- Terry

To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-chat" in the body of the message




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?3D365C37.ED032A35>