Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Languages / Managed C++ / October 2007

Tip: Looking for answers? Try searching our database.

AddRef and Release function of COM inteface

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
George - 18 Oct 2007 13:41 GMT
Hello everyone,

I have noticed a lot of COM samples that the function AddRef and Release
function of COM inteface is not synchronized to make it thread safe when
dealing with adding/decreasing reference count.

Is it needed to synchronize AddRef and Release? Or the COM runtime
underlying implementation handles thread safe issue by itself (i.e.
transparent to upper layer COM server developer)

I am using Visual Studio 2005 to develop native (unmanaged C++) COM. No
other framework is used (e.g. ATL).

thanks in advance,
George
Crest Teethgel - 18 Oct 2007 19:46 GMT
> Is it needed to synchronize AddRef and Release? Or the COM runtime

Yes.
Why and how are described in Don Box's Essential COM (p. 53)
George - 19 Oct 2007 05:47 GMT
Thanks Crest,

I want to confirm with you that you mean we need to add thread safe
synchronization approach to AddRef and Release to make counter value thread
safe manually by developers (i.e. COM runtime engine does not provide such
function)?

regards,
George

> > Is it needed to synchronize AddRef and Release? Or the COM runtime
>
> Yes.
> Why and how are described in Don Box's Essential COM (p. 53)
Carl Daniel [VC++ MVP] - 19 Oct 2007 06:14 GMT
> Thanks Crest,
>
> I want to confirm with you that you mean we need to add thread safe
> synchronization approach to AddRef and Release to make counter value
> thread safe manually by developers (i.e. COM runtime engine does not
> provide such function)?

Yes, that's correct.  AddRef/Release are typically implemented using
InterlockedIncrement and InterlockedDecrement.

-cd
George - 20 Oct 2007 15:00 GMT
Thanks for all of your help, cd!

regards,
George

> > Thanks Crest,
> >
[quoted text clipped - 7 lines]
>
> -cd
Ben Voigt [C++ MVP] - 19 Oct 2007 15:40 GMT
> Thanks Crest,
>
[quoted text clipped - 3 lines]
> safe manually by developers (i.e. COM runtime engine does not provide such
> function)?

*If* you mark your component with the single-threaded or apartment threading
model then you needn't worry.

Other threading models need to use InterlockedXYZ functions as Carl
mentioned.

> regards,
> George
[quoted text clipped - 3 lines]
>> Yes.
>> Why and how are described in Don Box's Essential COM (p. 53)
George - 20 Oct 2007 15:01 GMT
Hi Ben,

I am interested to learn the basics of apartment thread model. Could you
recommend some learning materials?

regards,
George

> > Thanks Crest,
> >
[quoted text clipped - 17 lines]
> >> Yes.
> >> Why and how are described in Don Box's Essential COM (p. 53)
Alex - 22 Oct 2007 05:43 GMT
http://www.codeproject.com/com/#COM
Signature

Thanks & Regards,
Alex.

> Hi Ben,
>
[quoted text clipped - 25 lines]
> > >> Yes.
> > >> Why and how are described in Don Box's Essential COM (p. 53)
Alex - 22 Oct 2007 05:44 GMT
http://www.codeproject.com/com/#COM
Signature

Thanks & Regards,
Alex.

> Hi Ben,
>
[quoted text clipped - 25 lines]
> > >> Yes.
> > >> Why and how are described in Don Box's Essential COM (p. 53)
George - 22 Oct 2007 07:25 GMT
Thanks Alex,

regards,
George

> http://www.codeproject.com/com/#COM
>
[quoted text clipped - 27 lines]
> > > >> Yes.
> > > >> Why and how are described in Don Box's Essential COM (p. 53)

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.