Hello everyone,


As mentioned in the book ATL Internals, when assign none to COM thread model,

--------------------
If there is no ThreadingModel given in the registry, COM will assume a
legacy single-threaded class and access the class object from the process's
first STA, creating a new STA is necessary. This protects objects from having
to synchronize access to global, static, or instance data.
--------------------

I do not understand why "This protects objects from having to synchronize
access to global, static, or instance data"? Any ideas?


thanks in advance,
George

Re: assign none to COM thread model by Igor

Igor
Thu Apr 10 22:08:18 CDT 2008

"George" <George@discussions.microsoft.com> wrote in message
news:55D261B0-5AEB-43E0-8CF0-D66387CB9092@microsoft.com
> As mentioned in the book ATL Internals, when assign none to COM
> thread model,
>
> --------------------
> If there is no ThreadingModel given in the registry, COM will assume a
> legacy single-threaded class and access the class object from the
> process's first STA, creating a new STA is necessary. This protects
> objects from having to synchronize access to global, static, or
> instance data. --------------------
>
> I do not understand why "This protects objects from having to
> synchronize access to global, static, or instance data"? Any ideas?

A regular STA object doesn't need to synchronize access to its instance
data, because it's always called on the same thread. But it still needs
to protect any shared global data (e.g. static data members), because
different instances may be created on different threads, so any shared
data may be accessed concurrently.

For legacy single-threaded components, COM arranges for all instances to
be created on the same designated thread. So there is never concurrent
access to any data.
--
With best wishes,
Igor Tandetnik

With sufficient thrust, pigs fly just fine. However, this is not
necessarily a good idea. It is hard to be sure where they are going to
land, and it could be dangerous sitting under them as they fly
overhead. -- RFC 1925



Re: assign none to COM thread model by George

George
Thu Apr 10 23:20:00 CDT 2008

Thanks Igor,


Question answered.


regards,
George

"Igor Tandetnik" wrote:

> "George" <George@discussions.microsoft.com> wrote in message
> news:55D261B0-5AEB-43E0-8CF0-D66387CB9092@microsoft.com
> > As mentioned in the book ATL Internals, when assign none to COM
> > thread model,
> >
> > --------------------
> > If there is no ThreadingModel given in the registry, COM will assume a
> > legacy single-threaded class and access the class object from the
> > process's first STA, creating a new STA is necessary. This protects
> > objects from having to synchronize access to global, static, or
> > instance data. --------------------
> >
> > I do not understand why "This protects objects from having to
> > synchronize access to global, static, or instance data"? Any ideas?
>
> A regular STA object doesn't need to synchronize access to its instance
> data, because it's always called on the same thread. But it still needs
> to protect any shared global data (e.g. static data members), because
> different instances may be created on different threads, so any shared
> data may be accessed concurrently.
>
> For legacy single-threaded components, COM arranges for all instances to
> be created on the same designated thread. So there is never concurrent
> access to any data.
> --
> With best wishes,
> Igor Tandetnik
>
> With sufficient thrust, pigs fly just fine. However, this is not
> necessarily a good idea. It is hard to be sure where they are going to
> land, and it could be dangerous sitting under them as they fly
> overhead. -- RFC 1925
>
>
>