473,657 Members | 2,405 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Re: acquire barrier for atomic reference counting

On 16 ÍÁÊ, 21:41, "Dmitriy V'jukov" <dvyu...@gmail. comwrote:
Can you clarify about atomic_global_f ence_compatibil ity.

1.10/7 (N2521)
"An evaluation A that performs a release operation on an object M
synchronizes with an evaluation B that performs an acquire operation
on M and reads a value written by any side effect in the release
sequence headed by A."

Release operation is performed on 'obj->rc' and acquire operation is
performed on 'std::atomic_gl obal_fence_comp atibility'. So why the
former 'synchronizes with' the latter?

According to definition, release operation on
'std::atomic_gl obal_fence_comp atibility' can only 'synchronize with'
acquire operation on 'std::atomic_gl obal_fence_comp atibility'.
Imho, it's a bit senseless. I think that I miss something. Can
somebody clarify about std::atomic_glo bal_fence_compa tibility?
Dmitriy V'jukov
Jun 27 '08 #1
10 2344
On May 17, 4:07 pm, "Dmitriy V'jukov" <dvyu...@gmail. comwrote:
On 16 ÍÁÊ, 21:41, "Dmitriy V'jukov" <dvyu...@gmail. comwrote:
Can you clarify about atomic_global_f ence_compatibil ity.
1.10/7 (N2521)
"An evaluation A that performs a release operation on an object M
synchronizes with an evaluation B that performs an acquire operation
on M and reads a value written by any side effect in the release
sequence headed by A."
Release operation is performed on 'obj->rc' and acquire operation is
performed on 'std::atomic_gl obal_fence_comp atibility'. So why the
former 'synchronizes with' the latter?

According to definition, release operation on
'std::atomic_gl obal_fence_comp atibility' can only 'synchronize with'
acquire operation on 'std::atomic_gl obal_fence_comp atibility'.
Imho, it's a bit senseless. I think that I miss something. Can
somebody clarify about std::atomic_glo bal_fence_compa tibility?
It's a global fence (see 29.3p11 in N2588). If that's not clear, then
that's a defect.

Anthony
Jun 27 '08 #2
"Dmitriy V'jukov" <dv*****@gmail. comwrites:
My current understanding is that:
1. atomic_global_f ence_compatibil ity must have some special treatment
from language.
or
2. it's useless.
My understanding is #1: it has special treatment. Use of this variable
for a fence is equivalent to a global fence instruction.

Anthony
--
Anthony Williams | Just Software Solutions Ltd
Custom Software Development | http://www.justsoftwaresolutions.co.uk
Registered in England, Company Number 5478976.
Registered Office: 15 Carrallack Mews, St Just, Cornwall, TR19 7UL
Jun 27 '08 #3
On May 20, 6:15 pm, "Dmitriy V'jukov" <dvyu...@gmail. comwrote:
2. Acquire operation must read value in 'release-sequence' of release
operation. What value "reads" fence() function? Since fence() is RMW
atomic operation, it must "read" some value. But how can I find out
what value it reads?
Btw, this applies to atomic_fence() function in general - what value
it "reads"?
If I don't know what value it reads then I can't be sure that
something 'synchronized-with'.

Dmitriy V'jukov
Jun 27 '08 #4
On May 20, 6:20 pm, anthony....@gma il.com wrote:
"Dmitriy V'jukov" <dvyu...@gmail. comwrites:
My current understanding is that:
1. atomic_global_f ence_compatibil ity must have some special treatment
from language.
or
2. it's useless.

My understanding is #1: it has special treatment. Use of this variable
for a fence is equivalent to a global fence instruction.
Where this 'special treatment' formally described?
29.4/11 (N2588) says only "... may be used to emulate global fences".
And 29.4/11 a *Note*.
I don't see any 'special treatment'. And according to 1.10 your
example is broken...

Dmitriy V'jukov
Jun 27 '08 #5
"Dmitriy V'jukov" <dv*****@gmail. comwrites:
On May 20, 6:15 pm, "Dmitriy V'jukov" <dvyu...@gmail. comwrote:
>2. Acquire operation must read value in 'release-sequence' of release
operation. What value "reads" fence() function? Since fence() is RMW
atomic operation, it must "read" some value. But how can I find out
what value it reads?

Btw, this applies to atomic_fence() function in general - what value
it "reads"?
You apply a fence on a specific variable, and it "reads" one of the
values written to the variable by some thread. A fence is a RMW
operation that writes the same value back.
If I don't know what value it reads then I can't be sure that
something 'synchronized-with'.
True. Fences need to be used carefully, and in combination with other
operations.

Anthony
--
Anthony Williams | Just Software Solutions Ltd
Custom Software Development | http://www.justsoftwaresolutions.co.uk
Registered in England, Company Number 5478976.
Registered Office: 15 Carrallack Mews, St Just, Cornwall, TR19 7UL
Jun 27 '08 #6
"Dmitriy V'jukov" <dv*****@gmail. comwrites:
On May 20, 6:20 pm, anthony....@gma il.com wrote:
>"Dmitriy V'jukov" <dvyu...@gmail. comwrites:
My current understanding is that:
1. atomic_global_f ence_compatibil ity must have some special treatment
from language.
or
2. it's useless.

My understanding is #1: it has special treatment. Use of this variable
for a fence is equivalent to a global fence instruction.

Where this 'special treatment' formally described?
29.4/11 (N2588) says only "... may be used to emulate global fences".
And 29.4/11 a *Note*.
I don't see any 'special treatment'. And according to 1.10 your
example is broken...
I've raised the issue on the LWG reflector. I'll let you know what
others say.

Anthony
--
Anthony Williams | Just Software Solutions Ltd
Custom Software Development | http://www.justsoftwaresolutions.co.uk
Registered in England, Company Number 5478976.
Registered Office: 15 Carrallack Mews, St Just, Cornwall, TR19 7UL
Jun 27 '08 #7
On May 20, 7:12 pm, anthony....@gma il.com wrote:
"Dmitriy V'jukov" <dvyu...@gmail. comwrites:
On May 20, 6:15 pm, "Dmitriy V'jukov" <dvyu...@gmail. comwrote:
2. Acquire operation must read value in 'release-sequence' of release
operation. What value "reads" fence() function? Since fence() is RMW
atomic operation, it must "read" some value. But how can I find out
what value it reads?
Btw, this applies to atomic_fence() function in general - what value
it "reads"?

You apply a fence on a specific variable, and it "reads" one of the
values written to the variable by some thread. A fence is a RMW
operation that writes the same value back.
If I don't know what value it reads then I can't be sure that
something 'synchronized-with'.

True. Fences need to be used carefully, and in combination with other
operations.

Ok. In following example I know what value fence operation will
"read". And luckily 'release sequence' is still not broken when
acquire operation executes.

void release(T* obj)
{
int rc = obj->rc.fetch_add (-1, memory_order_re lease) - 1;
if (0 == rc)
{
if (0 == obj->rc.fence(memor y_order_acquire ))
delete obj;
else
assert(false);
}
}
But let's consider Paul McKenney's motivating example from N2153
(http://www.open-std.org/jtc1/sc22/wg...07/n2153.pdf):

for (i=0; i< num_mailboxes; i++)
{
if (mailbox[i].load_raw() == my_id)
{
acquire_fence() ; // Prevents speculation of memory do_work(i);
// accesses in do_work
}
}

The goal is to remove acquire fence from every load. And issue acquire
fence only when there is real work to do.

As I understand following code won't work:

for (i=0; i< num_mailboxes; i++)
{
if (mailbox[i].load(std::memo ry_order_relaxe d) == my_id)
{
mailbox[i].fence(std::mem ory_order_acqui re); // Prevents
speculation of memory do_work(i);
// accesses in do_work
}
}

Because 'release sequence' is just broken by relaxed load. Right?

This code will work if definition of 'synchronizes with' will be
changed from:

"An evaluation A that performs a release operation on an object M
synchronizes with an evaluation B that performs an acquire operation
on M and reads a value written by any side effect in the release
sequence headed by A."

to:

"An evaluation A that performs a release operation on an object M
synchronizes with an evaluation B that performs an acquire operation
on M and B *or any expression sequenced before B* reads a value
written by any side effect in the release sequence headed by A."

What do you think?

Dmitriy V'jukov
Jun 27 '08 #8
"Dmitriy V'jukov" <dv*****@gmail. comwrites:
Ok. In following example I know what value fence operation will
"read". And luckily 'release sequence' is still not broken when
acquire operation executes.

void release(T* obj)
{
int rc = obj->rc.fetch_add (-1, memory_order_re lease) - 1;
if (0 == rc)
{
if (0 == obj->rc.fence(memor y_order_acquire ))
delete obj;
else
assert(false);
}
}
I'm happy that this example is fine.
But let's consider Paul McKenney's motivating example from N2153
(http://www.open-std.org/jtc1/sc22/wg...07/n2153.pdf):

for (i=0; i< num_mailboxes; i++)
{
if (mailbox[i].load_raw() == my_id)
{
acquire_fence() ; // Prevents speculation of memory do_work(i);
// accesses in do_work
}
}

The goal is to remove acquire fence from every load. And issue acquire
fence only when there is real work to do.

As I understand following code won't work:

for (i=0; i< num_mailboxes; i++)
{
if (mailbox[i].load(std::memo ry_order_relaxe d) == my_id)
{
mailbox[i].fence(std::mem ory_order_acqui re); // Prevents
speculation of memory do_work(i);
// accesses in do_work
}
}

Because 'release sequence' is just broken by relaxed load. Right?
The relaxed load is just that: a load. It therefore does not feature
in the "modificati on sequence" of mailbox[i], and does not break the
release sequence. Therefore the store/release that writes mailbox[i]
can still synchronize-with the fence.

I think this example does in fact work.
This code will work if definition of 'synchronizes with' will be
changed from:

"An evaluation A that performs a release operation on an object M
synchronizes with an evaluation B that performs an acquire operation
on M and reads a value written by any side effect in the release
sequence headed by A."

to:

"An evaluation A that performs a release operation on an object M
synchronizes with an evaluation B that performs an acquire operation
on M and B *or any expression sequenced before B* reads a value
written by any side effect in the release sequence headed by A."

What do you think?
I think that is unnecessary. A relaxed load doesn't interfere with the
release sequence or the modification sequence, and if the relaxed load
sees the value, a subsequent acquire on the same thread can only see
that value or a later value (1.10p10 in N2588).

Anthony
--
Anthony Williams | Just Software Solutions Ltd
Custom Software Development | http://www.justsoftwaresolutions.co.uk
Registered in England, Company Number 5478976.
Registered Office: 15 Carrallack Mews, St Just, Cornwall, TR19 7UL
Jun 27 '08 #9
On May 20, 8:35 pm, anthony....@gma il.com wrote:
Because 'release sequence' is just broken by relaxed load. Right?

The relaxed load is just that: a load. It therefore does not feature
in the "modificati on sequence" of mailbox[i], and does not break the
release sequence. Therefore the store/release that writes mailbox[i]
can still synchronize-with the fence.

Yikes! You are right!

I think this example does in fact work.

Ok. Things start clearing up :)

This code will work if definition of 'synchronizes with' will be
changed from:
"An evaluation A that performs a release operation on an object M
synchronizes with an evaluation B that performs an acquire operation
on M and reads a value written by any side effect in the release
sequence headed by A."
to:
"An evaluation A that performs a release operation on an object M
synchronizes with an evaluation B that performs an acquire operation
on M and B *or any expression sequenced before B* reads a value
written by any side effect in the release sequence headed by A."
What do you think?

I think that is unnecessary. A relaxed load doesn't interfere with the
release sequence or the modification sequence, and if the relaxed load
sees the value, a subsequent acquire on the same thread can only see
that value or a later value (1.10p10 in N2588).

Yes, it already works figuratively this way:
1. Load function 'reads the value'
2. Subsequent acquire fence 'performs an acquire operation'
Dmitriy V'jukov
Jun 27 '08 #10

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

Similar topics

6
2174
by: Elbert Lev | last post by:
Please correct me if I'm wrong. Python (as I understand) uses reference counting to determine when to delete the object. As soon as the object goes out of the scope it is deleted. Python does not use garbage collection (as Java does). So if the script runs a loop: for i in range(100): f = Obj(i)
8
3572
by: Glenn Kasten | last post by:
I am wondering which operations in Python are guaranteed to be atomic in the presence of multi-threading. In particular, are assignment and reading of a dictionary entry atomic? For example, initially: dictionary = {} dictionary = old_value Then thread 1 does: v = dictionary And thread 2 does:
1
3247
by: Tony Johansson | last post by:
Hello Experts! I reading a book called programming with design pattern revealed by Tomasz Muldner and here I read something that I don't understand completely. It says "A garbarage collector, such as the one used in Java, maintains a record of whether or not an object is currentlys being used. An unused object is tagged as garbage,
5
2163
by: hikums | last post by:
Begin Atomic Declare a integer; Set a=(select count(1) from claims.table1); if a<>0 then import into c:\tmptyfile.txt of del replace into claims.table1; end if; End!
31
5850
by: William Stacey [MVP] | last post by:
Here is an interesting writing on memory barriers. Not sure if this helps my understanding or raises more questions, but interesting... http://discuss.develop.com/archives/wa.exe?A2=ind0203B&L=DOTNET&P=R375 -- William Stacey, MVP
4
4193
by: aaronfude | last post by:
Hi, Please consider the following class (it's not really my class, but it's a good example for my question): class Vector { int myN; double *myX; Vector(int n) : myN(n), myX(new double) { } double &operator()(int i) { return myX; }
3
2239
by: Ole Nielsby | last post by:
I need to implement reference counting in a class hierarch, in a thread safe manner. (The classes are umanaged but I might want to compile them with the /clr option.) Some of the objects - atoms - are registered in a global hash table - let's call it an atom table. When an atom refernce count reaches zero, the atom is removed from the table. The catch is, after an atom has been counted down, another thread might find it in the atom...
1
2271
by: oec.deepak | last post by:
Hi Cn any one telll me what is Reference counting in C++.
11
6325
by: Jon Harrop | last post by:
Can read locks on a data structure be removed safely when updates are limited to replacing a reference? In other words, is setting a reference an atomic operation? I have been assuming that all writes of <=1 word of data are atomic. Is this actually documented anywhere? -- Dr Jon D Harrop, Flying Frog Consultancy http://www.ffconsultancy.com/products/?u
0
8420
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8842
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8740
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8516
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8617
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6176
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4173
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4330
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2743
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

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.