473,320 Members | 1,846 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

AddRef and Release function of COM inteface

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
Oct 18 '07 #1
9 1624
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)
Oct 18 '07 #2
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

"Crest Teethgel" wrote:
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)
Oct 19 '07 #3
George wrote:
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
Oct 19 '07 #4

"George" <Ge****@discussions.microsoft.comwrote in message
news:67**********************************@microsof t.com...
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)?
*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

"Crest Teethgel" wrote:
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)

Oct 19 '07 #5
Thanks for all of your help, cd!
regards,
George

"Carl Daniel [VC++ MVP]" wrote:
George wrote:
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
Oct 20 '07 #6
Hi Ben,
I am interested to learn the basics of apartment thread model. Could you
recommend some learning materials?
regards,
George

"Ben Voigt [C++ MVP]" wrote:
>
"George" <Ge****@discussions.microsoft.comwrote in message
news:67**********************************@microsof t.com...
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)?

*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

"Crest Teethgel" wrote:
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)


Oct 20 '07 #7
http://www.codeproject.com/com/#COM
--
Thanks & Regards,
Alex.
"George" wrote:
Hi Ben,
I am interested to learn the basics of apartment thread model. Could you
recommend some learning materials?
regards,
George

"Ben Voigt [C++ MVP]" wrote:

"George" <Ge****@discussions.microsoft.comwrote in message
news:67**********************************@microsof t.com...
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)?
*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
>
"Crest Teethgel" wrote:
>
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)
>>
Oct 22 '07 #8
http://www.codeproject.com/com/#COM
--
Thanks & Regards,
Alex.
"George" wrote:
Hi Ben,
I am interested to learn the basics of apartment thread model. Could you
recommend some learning materials?
regards,
George

"Ben Voigt [C++ MVP]" wrote:

"George" <Ge****@discussions.microsoft.comwrote in message
news:67**********************************@microsof t.com...
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)?
*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
>
"Crest Teethgel" wrote:
>
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)
>>
Oct 22 '07 #9
Thanks Alex,
regards,
George

"Alex" wrote:
http://www.codeproject.com/com/#COM
--
Thanks & Regards,
Alex.
"George" wrote:
Hi Ben,
I am interested to learn the basics of apartment thread model. Could you
recommend some learning materials?
regards,
George

"Ben Voigt [C++ MVP]" wrote:
>
"George" <Ge****@discussions.microsoft.comwrote in message
news:67**********************************@microsof t.com...
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)?
>
*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

"Crest Teethgel" wrote:

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)
>
>
>
>
Oct 22 '07 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

10
by: rg | last post by:
Hi all, I was wondering if anyone had dealt with a similar problem. I need to use a template function as the parameter for a particular function (also template function). The program compiles...
2
by: NG | last post by:
Hi All, I want to declare an interface in C#. I have the equivalent code for VB.NET but when I try to write the corresponding code in C#, it does not work. Can anyone please help me by...
3
by: gemel | last post by:
Interface definitions do no not contain implementation, only signtures. That is there real purpose. Here thow we have an Inteface which does not have any implementation code but it has to be...
8
by: Marius Horak | last post by:
I've never used Interface and never will. But now I have to make major modifications to a large system where almost all classes are based on some kind of Interface. Hundreds of classes. When I...
1
by: Diogo Alves - Software Developer | last post by:
Greetings, I have a com object that cannot be released by the carbage collection, in c++ that object is created and then we add a AddRef(), and only when we need to release him we do Release()....
9
by: ypjofficial | last post by:
Hello All, I am defining a class with one virtual function and storing its first 4 bytes ie. the address of the virtual function table to a file.I am again rereading the file in the same program...
5
by: Filippo Bettinaglio | last post by:
I have a DLL written in C++ (unmanaged), which I want to inteface with. I created a standard window form program with VC++ 2005, all fine I have imported an .h file the .lib file and all works. ...
7
by: Markus Svilans | last post by:
Hello, My question involves virtual functions and inheritance. Suppose we have a class structure, that consists of "data" classes, and "processor" classes. The data classes are derived from...
15
by: Anna Smidt | last post by:
Hello! Sven told me I could come here if I have problems compiling. I am wondering if I can also post translation errors from VC6 to VC9 here. Thanks. Anna
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.