Rocksolid Light

Welcome to novaBBS (click a section below)

mail  files  register  newsreader  groups  login

Message-ID:  

24 Apr, 2024: Testing a new version of the Overboard here. If you have an issue post about it to rocksolid.nodes.help (I know. Everyone on Usenet has issues)


devel / comp.lang.c / Advanced (for me) Question About Keyword volatile

SubjectAuthor
* Advanced (for me) Question About Keyword volatiledas...@gmail.com
+* Re: Advanced (for me) Question About Keyword volatileChris M. Thomasson
|`* Re: Advanced (for me) Question About Keyword volatileBonita Montero
| `* Re: Advanced (for me) Question About Keyword volatileChris M. Thomasson
|  `* Re: Advanced (for me) Question About Keyword volatileBonita Montero
|   `* Re: Advanced (for me) Question About Keyword volatileChris M. Thomasson
|    `* Re: Advanced (for me) Question About Keyword volatileBonita Montero
|     +* Re: Advanced (for me) Question About Keyword volatileChris M. Thomasson
|     |`* Re: Advanced (for me) Question About Keyword volatileBonita Montero
|     | `* Re: Advanced (for me) Question About Keyword volatileChris M. Thomasson
|     |  `* Re: Advanced (for me) Question About Keyword volatileBonita Montero
|     |   `* Re: Advanced (for me) Question About Keyword volatileChris M. Thomasson
|     |    `* Re: Advanced (for me) Question About Keyword volatileBonita Montero
|     |     `- Re: Advanced (for me) Question About Keyword volatileChris M. Thomasson
|     `* Re: Advanced (for me) Question About Keyword volatileChris M. Thomasson
|      +* Re: Advanced (for me) Question About Keyword volatileBonita Montero
|      |`* Re: Advanced (for me) Question About Keyword volatileChris M. Thomasson
|      | `* Re: Advanced (for me) Question About Keyword volatileBonita Montero
|      |  `* Re: Advanced (for me) Question About Keyword volatileChris M. Thomasson
|      |   +- Re: Advanced (for me) Question About Keyword volatileBonita Montero
|      |   `* Re: Advanced (for me) Question About Keyword volatileBonita Montero
|      |    `* Re: Advanced (for me) Question About Keyword volatileChris M. Thomasson
|      |     `* Re: Advanced (for me) Question About Keyword volatileBonita Montero
|      |      `* Re: Advanced (for me) Question About Keyword volatileChris M. Thomasson
|      |       `* Re: Advanced (for me) Question About Keyword volatileBonita Montero
|      |        `* Re: Advanced (for me) Question About Keyword volatileChris M. Thomasson
|      |         `* Re: Advanced (for me) Question About Keyword volatileBonita Montero
|      |          `* Re: Advanced (for me) Question About Keyword volatileChris M. Thomasson
|      |           `* Re: Advanced (for me) Question About Keyword volatileBonita Montero
|      |            `- Re: Advanced (for me) Question About Keyword volatileChris M. Thomasson
|      `* Re: Advanced (for me) Question About Keyword volatileChris M. Thomasson
|       `- Re: Advanced (for me) Question About Keyword volatileBonita Montero
+* Re: Advanced (for me) Question About Keyword volatileManfred
|`- Re: Advanced (for me) Question About Keyword volatileChris M. Thomasson
+- Re: Advanced (for me) Question About Keyword volatileDavid Brown
+* Re: Advanced (for me) Question About Keyword volatileÖö Tiib
|`* Re: Advanced (for me) Question About Keyword volatileJorgen Grahn
| `- Re: Advanced (for me) Question About Keyword volatileKaz Kylheku
`* Re: Advanced (for me) Question About Keyword volatileBonita Montero
 `* Re: Advanced (for me) Question About Keyword volatileChris M. Thomasson
  `* Re: Advanced (for me) Question About Keyword volatileBonita Montero
   `* Re: Advanced (for me) Question About Keyword volatileChris M. Thomasson
    `* Re: Advanced (for me) Question About Keyword volatileBonita Montero
     `* Re: Advanced (for me) Question About Keyword volatileChris M. Thomasson
      `* Re: Advanced (for me) Question About Keyword volatileBonita Montero
       `- Re: Advanced (for me) Question About Keyword volatileChris M. Thomasson

Pages:12
Advanced (for me) Question About Keyword volatile

<4eddd378-e045-4242-bf9e-bc0efae0cea5n@googlegroups.com>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=20598&group=comp.lang.c#20598

  copy link   Newsgroups: comp.lang.c
X-Received: by 2002:a37:ac07:0:b0:649:63d5:6154 with SMTP id e7-20020a37ac07000000b0064963d56154mr9548649qkm.274.1646001326210;
Sun, 27 Feb 2022 14:35:26 -0800 (PST)
X-Received: by 2002:a05:622a:50f:b0:2de:736c:8df with SMTP id
l15-20020a05622a050f00b002de736c08dfmr14448002qtx.20.1646001326020; Sun, 27
Feb 2022 14:35:26 -0800 (PST)
Path: i2pn2.org!i2pn.org!weretis.net!feeder6.news.weretis.net!1.us.feeder.erje.net!2.us.feeder.erje.net!3.us.feeder.erje.net!feeder.erje.net!border1.nntp.dca1.giganews.com!nntp.giganews.com!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.lang.c
Date: Sun, 27 Feb 2022 14:35:25 -0800 (PST)
Injection-Info: google-groups.googlegroups.com; posting-host=68.43.68.255; posting-account=_fjjBwoAAACf5uWL0FWgR46LXP5X2qYB
NNTP-Posting-Host: 68.43.68.255
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <4eddd378-e045-4242-bf9e-bc0efae0cea5n@googlegroups.com>
Subject: Advanced (for me) Question About Keyword volatile
From: dash...@gmail.com (das...@gmail.com)
Injection-Date: Sun, 27 Feb 2022 22:35:26 +0000
Content-Type: text/plain; charset="UTF-8"
Lines: 55
 by: das...@gmail.com - Sun, 27 Feb 2022 22:35 UTC

I have 3 variables used as interface variables between 2 threads. Thread A writes the variables, and Thread B reads them. Let me call them v1, v2, and v3.

I buffer (or snapshot) them into local variables.

Question: Do the local variables need to be declared volatile as well?

Thanks, Dave A.

Code below.

-----

volatile int v1;
volatile int v2;
volatile int v3;

void ThreadA(void) //Writes the variables.
{ //3 critical sections, but doesn't matter if ThreadB()
//obtains values not obtained at exactly the same
//time.
...
MUTEX_BEGIN();
v1 = expression1;
MUTEX_END();
...
MUTEX_BEGIN();
v2 = expression2;
MUTEX_END();
...
MUTEX_BEGIN();
v3 = expression3;
MUTEX_END();
}

void ThreadB(void) //Reads/uses the variables.
{ /* volatile???? */ int buf_v1, buf_v2, buf_v3;
//My Question: Is there any necessity to declare the 3
//buffer variables above volatile, or does the
//"sequence point" behavior of volatile v1, v2, and v3
//provide a strong enough guarantee? In other words,
//are buf_v1, buf_v2, and buf_v3 guaranteed assigned
//before MUTEX_END()?
...
MUTEX_BEGIN();
buf_v1 = v1;
buf_v2 = v2;
buf_v3 = v3;
MUTEX_END();

...
... //Miscellaneous tests and reads involving
... //buf_v1, buf_v2, and buf_v3.
...
}

Re: Advanced (for me) Question About Keyword volatile

<svh461$3jf$1@dont-email.me>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=20599&group=comp.lang.c#20599

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: chris.m....@gmail.com (Chris M. Thomasson)
Newsgroups: comp.lang.c
Subject: Re: Advanced (for me) Question About Keyword volatile
Date: Sun, 27 Feb 2022 16:14:54 -0800
Organization: A noiseless patient Spider
Lines: 15
Message-ID: <svh461$3jf$1@dont-email.me>
References: <4eddd378-e045-4242-bf9e-bc0efae0cea5n@googlegroups.com>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Mon, 28 Feb 2022 00:14:57 -0000 (UTC)
Injection-Info: reader02.eternal-september.org; posting-host="332d083a87aec92f7feea1ff8fa83796";
logging-data="3695"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+Z0KrMND1XtZ8pFrIotVNsFbwGG1ZEmDE="
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:91.0) Gecko/20100101
Thunderbird/91.6.1
Cancel-Lock: sha1:M+Ndv3S1IHaOmP86Sk64V9nrJGs=
In-Reply-To: <4eddd378-e045-4242-bf9e-bc0efae0cea5n@googlegroups.com>
Content-Language: en-US
 by: Chris M. Thomasson - Mon, 28 Feb 2022 00:14 UTC

On 2/27/2022 2:35 PM, das...@gmail.com wrote:
> I have 3 variables used as interface variables between 2 threads. Thread A writes the variables, and Thread B reads them. Let me call them v1, v2, and v3.
>
> I buffer (or snapshot) them into local variables.
>
> Question: Do the local variables need to be declared volatile as well?

The local variables are fine, and do not need to be atomic/volatile,
ect... Btw, think about using C atomic's instead of volatile. You might
be interested in a seqlock:

https://en.wikipedia.org/wiki/Seqlock
(read all)

They are geared to a read-mostly, write rarely pattern.

Re: Advanced (for me) Question About Keyword volatile

<svh4ru$vp0$1@gioia.aioe.org>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=20600&group=comp.lang.c#20600

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!aioe.org!Puiiztk9lHEEQC0y3uUjRA.user.46.165.242.75.POSTED!not-for-mail
From: non...@add.invalid (Manfred)
Newsgroups: comp.lang.c
Subject: Re: Advanced (for me) Question About Keyword volatile
Date: Mon, 28 Feb 2022 01:26:38 +0100
Organization: Aioe.org NNTP Server
Message-ID: <svh4ru$vp0$1@gioia.aioe.org>
References: <4eddd378-e045-4242-bf9e-bc0efae0cea5n@googlegroups.com>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Info: gioia.aioe.org; logging-data="32544"; posting-host="Puiiztk9lHEEQC0y3uUjRA.user.gioia.aioe.org"; mail-complaints-to="abuse@aioe.org";
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:91.0) Gecko/20100101
Thunderbird/91.6.1
Content-Language: en-US
X-Notice: Filtered by postfilter v. 0.9.2
 by: Manfred - Mon, 28 Feb 2022 00:26 UTC

On 2/27/2022 11:35 PM, das...@gmail.com wrote:
> I have 3 variables used as interface variables between 2 threads. Thread A writes the variables, and Thread B reads them. Let me call them v1, v2, and v3.
>
> I buffer (or snapshot) them into local variables.
>
> Question: Do the local variables need to be declared volatile as well?
>
> Thanks, Dave A.
>
> Code below.
>
> -----
>
> volatile int v1;
> volatile int v2;
> volatile int v3;
>
> void ThreadA(void) //Writes the variables.
> {
> //3 critical sections, but doesn't matter if ThreadB()
> //obtains values not obtained at exactly the same
> //time.
> ...
> MUTEX_BEGIN();
> v1 = expression1;
> MUTEX_END();
> ...
> MUTEX_BEGIN();
> v2 = expression2;
> MUTEX_END();
> ...
> MUTEX_BEGIN();
> v3 = expression3;
> MUTEX_END();
> }
>
> void ThreadB(void) //Reads/uses the variables.
> {
> /* volatile???? */ int buf_v1, buf_v2, buf_v3;
> //My Question: Is there any necessity to declare the 3
> //buffer variables above volatile, or does the
> //"sequence point" behavior of volatile v1, v2, and v3
> //provide a strong enough guarantee? In other words,
> //are buf_v1, buf_v2, and buf_v3 guaranteed assigned
> //before MUTEX_END()?
> ...
> MUTEX_BEGIN();
> buf_v1 = v1;
> buf_v2 = v2;
> buf_v3 = v3;
> MUTEX_END();
>
> ...
> ... //Miscellaneous tests and reads involving
> ... //buf_v1, buf_v2, and buf_v3.
> ...
> }

I'm not a fan of this use of volatile[*], and as a consequence I am not
that much of an expert either, however:

1) The buf_v1/v2/v3 variables need not be volatile, since both read and
write access to v1/v2/v3 is protected by memory barriers due to their
volatile qualifiers.

2) If you synchronize access to v1/v2/v3 with mutexes you don't need to
make them volatile either.

[*] the volatile keyword was introduced in C for a somewhat different
purpose than multithreaded access, although it may work for this purpose
too under some conditions.
The proper way to handle multithreaded read/write is atomics in modern
C, or locking (mutexes etc.)

Re: Advanced (for me) Question About Keyword volatile

<svh6oi$j3o$1@dont-email.me>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=20601&group=comp.lang.c#20601

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: chris.m....@gmail.com (Chris M. Thomasson)
Newsgroups: comp.lang.c
Subject: Re: Advanced (for me) Question About Keyword volatile
Date: Sun, 27 Feb 2022 16:58:55 -0800
Organization: A noiseless patient Spider
Lines: 141
Message-ID: <svh6oi$j3o$1@dont-email.me>
References: <4eddd378-e045-4242-bf9e-bc0efae0cea5n@googlegroups.com>
<svh4ru$vp0$1@gioia.aioe.org>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
Injection-Date: Mon, 28 Feb 2022 00:58:58 -0000 (UTC)
Injection-Info: reader02.eternal-september.org; posting-host="332d083a87aec92f7feea1ff8fa83796";
logging-data="19576"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/j0XDVMgCY4hDZE1urbFslDHyh5caJbpc="
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:91.0) Gecko/20100101
Thunderbird/91.6.1
Cancel-Lock: sha1:1m4+FMvvN6W9MgutawMkLH9Rsrs=
In-Reply-To: <svh4ru$vp0$1@gioia.aioe.org>
Content-Language: en-US
 by: Chris M. Thomasson - Mon, 28 Feb 2022 00:58 UTC

On 2/27/2022 4:26 PM, Manfred wrote:
> On 2/27/2022 11:35 PM, das...@gmail.com wrote:
>> I have 3 variables used as interface variables between 2 threads.
>> Thread A writes the variables, and Thread B reads them.  Let me call
>> them v1, v2, and v3.
>>
>> I buffer (or snapshot) them into local variables.
>>
>> Question:  Do the local variables need to be declared volatile as well?
>>
>> Thanks, Dave A.
>>
>> Code below.
>>
>> -----
>>
>> volatile int v1;
>> volatile int v2;
>> volatile int v3;
>>
>> void ThreadA(void)  //Writes the variables.
>> {
>>     //3 critical sections, but doesn't matter if ThreadB()
>>     //obtains values not obtained at exactly the same
>>     //time.
>>     ...
>>     MUTEX_BEGIN();
>>     v1 = expression1;
>>     MUTEX_END();
>>     ...
>>     MUTEX_BEGIN();
>>     v2 = expression2;
>>     MUTEX_END();
>>     ...
>>     MUTEX_BEGIN();
>>     v3 = expression3;
>>     MUTEX_END();
>> }
>>
>> void ThreadB(void)  //Reads/uses the variables.
>> {
>>     /* volatile???? */ int buf_v1, buf_v2, buf_v3;
>>     //My Question:  Is there any necessity to declare the 3
>>     //buffer variables above volatile, or does the
>>     //"sequence point" behavior of volatile v1, v2, and v3
>>     //provide a strong enough guarantee?  In other words,
>>     //are buf_v1, buf_v2, and buf_v3 guaranteed assigned
>>     //before MUTEX_END()?
>>     ...
>>     MUTEX_BEGIN();
>>     buf_v1 = v1;
>>     buf_v2 = v2;
>>     buf_v3 = v3;
>>     MUTEX_END();
>>
>>     ...
>>     ... //Miscellaneous tests and reads involving
>>     ... //buf_v1, buf_v2, and buf_v3.
>>     ...
>> }
>
> I'm not a fan of this use of volatile[*], and as a consequence I am not
> that much of an expert either, however:
>
> 1) The buf_v1/v2/v3 variables need not be volatile, since both read and
> write access to v1/v2/v3 is protected by memory barriers due to their
> volatile qualifiers.
>
> 2) If you synchronize access to v1/v2/v3 with mutexes you don't need to
> make them volatile either.
>
> [*] the volatile keyword was introduced in C for a somewhat different
> purpose than multithreaded access, although it may work for this purpose
> too under some conditions.
> The proper way to handle multithreaded read/write is atomics in modern
> C, or locking (mutexes etc.)

Think of the following scenario:

// pseudo code
_____________________________
atomic_int g_a = 0;
atomic_int g_b = 0;
atomic_int g_c = 0;

mtx_t g_lock;

void thread_a()
{ mtx_lock(&g_lock);
g_b = g_b + 1;
mtx_unlock(&g_lock);
}

void thread_b()
{ mtx_lock(&g_lock);
int a = atomic_load(&g_a, memory_order_relaxed);
mtx_unlock(&g_lock);
} _____________________________

Now, even though thread_b is acquiring the mutex, it still reads g_a
outside of mutex protection. This can be an interesting situation
because if thread_a decided to alter g_a outside of mutex protection,
then g_a needs to be atomic. So, to get at the bare bones wrt the
pseudo-code I posted:
_____________________________

atomic_int g_a = 0;
int g_b = 0;
int g_c = 0;

mtx_t g_lock;

void thread_a()
{ mtx_lock(&g_lock);
g_b = g_b + 1;
mtx_unlock(&g_lock);
}

void thread_b()
{ mtx_lock(&g_lock);
int a = atomic_load(&g_a, memory_order_relaxed);
int b = g_b; // does not need to be atomic.
mtx_unlock(&g_lock);
} _____________________________

This works fine, as long as you are not dependent on any external data
wrt g_a. Then, an acquire might be in order wrt loading from g_a.

Iirc volatile does not guarantee anything wrt memory visibility. Use C
atomics.

Re: Advanced (for me) Question About Keyword volatile

<svi17p$lc0$1@dont-email.me>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=20603&group=comp.lang.c#20603

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: david.br...@hesbynett.no (David Brown)
Newsgroups: comp.lang.c
Subject: Re: Advanced (for me) Question About Keyword volatile
Date: Mon, 28 Feb 2022 09:30:48 +0100
Organization: A noiseless patient Spider
Lines: 75
Message-ID: <svi17p$lc0$1@dont-email.me>
References: <4eddd378-e045-4242-bf9e-bc0efae0cea5n@googlegroups.com>
Mime-Version: 1.0
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: 7bit
Injection-Date: Mon, 28 Feb 2022 08:30:49 -0000 (UTC)
Injection-Info: reader02.eternal-september.org; posting-host="cc5274f87f71e7bc30bc607f6985c5c8";
logging-data="21888"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19yUN2zqlLG8zqMWgcKTtn2ezTSQBKv+Dw="
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101
Thunderbird/78.11.0
Cancel-Lock: sha1:vUl9qpID0Ksts2QFpHCWbieuRgw=
In-Reply-To: <4eddd378-e045-4242-bf9e-bc0efae0cea5n@googlegroups.com>
Content-Language: en-GB
 by: David Brown - Mon, 28 Feb 2022 08:30 UTC

On 27/02/2022 23:35, das...@gmail.com wrote:
> I have 3 variables used as interface variables between 2 threads. Thread A writes the variables, and Thread B reads them. Let me call them v1, v2, and v3.
>
> I buffer (or snapshot) them into local variables.
>
> Question: Do the local variables need to be declared volatile as well?
>
> Thanks, Dave A.
>
> Code below.

To understand "volatile", you should think in terms of volatile
/accesses/, not volatile /objects/. Think of an object that is declared
"volatile" as simply being one for which all accesses must be volatile.

You also need to understand that the compiler sees the generated object
as a sequence of instructions - it knows nothing about hardware
instruction scheduling, out-of-order execution, speculative execution,
read-ahead, write buffers, caches, multiple cores, or anything else.
Keep that in mind for these next few paragraphs.

A "volatile" access is observable behaviour - the compiler can't omit
it, add new ones, combine them or re-order them. So it gives an
ordering amongst other volatile accesses (and other observable behaviour
such as file I/O, or things that /might/ have observable behaviour such
as calling a function the compiler knows nothing about).

When you have :

volatile int v1, v2;

then
buf_v1 = v1;
buf_v2 = v2;

the compiler must generate an instruction to read "v1", and an
instruction to read "v2". The read of "v1" must come first, and there
can be no duplicate reads, or re-ordering with other volatile accesses.
What happens with the values it reads does not really matter. They can
be put in registers, or memory, or manipulated or thrown away. Since
"buf_v1" and "buf_v2" are not part of your interface, you don't care how
they are used at the low level. So there is no benefit in making them
"volatile".

If your program is to run on a target with a simple execution model -
with the key point being a single processor core - then you can use
"volatile" data like this. This is common in small-systems embedded
programming on microcontrollers. But obviously it does not apply to
anything on a bigger processor with more than one core - PC's, embedded
Linux, etc.

On a single-core processor you only need a mutex if you need atomic
consistency that is wider than the single-instruction access width for
the processor. Thus you don't need a mutex at all if the three
variables are independent (assuming your processor can handle an "int"
read or write in a single instruction).

If your program is running on a multi-core system, things get a /lot/
more complicated. Within a thread, the program will see volatile
accesses in the order the compiler generated them. But across threads,
which might be running on different cores, you have no such guarantees.
Volatile writes from one thread might never be seen at all on other
threads. So you need stronger controls that handle visibility across
threads, using atomics, fences, etc., and often you no longer need
"volatile" at all.

The best choice here can depend on the details of your tools, your
target, your OS. C11 atomics could be used, but only if you have C11
and good atomics support. Whatever implements "MUTEX_BEGIN" and
"MUTEX_END" might have support for other approaches.

Re: Advanced (for me) Question About Keyword volatile

<9ae58a92-76d6-4aff-840f-b4d359ab695fn@googlegroups.com>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=20604&group=comp.lang.c#20604

  copy link   Newsgroups: comp.lang.c
X-Received: by 2002:adf:82b4:0:b0:1ed:d109:bdf6 with SMTP id 49-20020adf82b4000000b001edd109bdf6mr16365569wrc.441.1646069254113;
Mon, 28 Feb 2022 09:27:34 -0800 (PST)
X-Received: by 2002:a37:bb02:0:b0:47c:9965:3b6b with SMTP id
l2-20020a37bb02000000b0047c99653b6bmr11889029qkf.190.1646069253899; Mon, 28
Feb 2022 09:27:33 -0800 (PST)
Path: i2pn2.org!i2pn.org!weretis.net!feeder6.news.weretis.net!news.misty.com!border2.nntp.dca1.giganews.com!nntp.giganews.com!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.lang.c
Date: Mon, 28 Feb 2022 09:27:33 -0800 (PST)
In-Reply-To: <4eddd378-e045-4242-bf9e-bc0efae0cea5n@googlegroups.com>
Injection-Info: google-groups.googlegroups.com; posting-host=84.50.190.130; posting-account=pysjKgkAAACLegAdYDFznkqjgx_7vlUK
NNTP-Posting-Host: 84.50.190.130
References: <4eddd378-e045-4242-bf9e-bc0efae0cea5n@googlegroups.com>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <9ae58a92-76d6-4aff-840f-b4d359ab695fn@googlegroups.com>
Subject: Re: Advanced (for me) Question About Keyword volatile
From: oot...@hot.ee (Öö Tiib)
Injection-Date: Mon, 28 Feb 2022 17:27:34 +0000
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
Lines: 25
 by: Öö Tiib - Mon, 28 Feb 2022 17:27 UTC

On Monday, 28 February 2022 at 00:35:56 UTC+2, das...@gmail.com wrote:
> I have 3 variables used as interface variables between 2 threads. Thread A writes the variables, and Thread B reads them. Let me call them v1, v2, and v3.
>
> I buffer (or snapshot) them into local variables.
>
> Question: Do the local variables need to be declared volatile as well?

The volatile keyword doesn’t give the right kind of control for multi-processor
or multi-thread synchronisation generally. It is meant for something else.
But implementor of particular C compiler can of course add there whatever
additional meanings that standard does not require.

By standard the compiler is allowed to migrate non-volatile accesses
above or below a volatile access. The compiler is not required to insert
memory barriers around volatile accesses. When there are no memory
barriers then the hardware can reorder them with respect to non-volatile
accesses despite whatever compiler did. The hardware can even reorder
two volatile accesses if the memory attributes permit it.

Therefore your volatile usage is either pointless or platform-specific repair
of defects in undisclosed MUTEX_BEGIN() and MUTEX_END().

Re: Advanced (for me) Question About Keyword volatile

<slrnt1qjk8.1rfm.grahn+nntp@frailea.sa.invalid>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=20607&group=comp.lang.c#20607

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!news.swapon.de!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail
From: grahn+n...@snipabacken.se (Jorgen Grahn)
Newsgroups: comp.lang.c
Subject: Re: Advanced (for me) Question About Keyword volatile
Date: 28 Feb 2022 22:36:56 GMT
Lines: 22
Message-ID: <slrnt1qjk8.1rfm.grahn+nntp@frailea.sa.invalid>
References: <4eddd378-e045-4242-bf9e-bc0efae0cea5n@googlegroups.com>
<9ae58a92-76d6-4aff-840f-b4d359ab695fn@googlegroups.com>
X-Trace: individual.net a3oZIYnQLrlluIaaO0bYHwOGrh1Ot1eii2gkuCYUiuUUiw6v1d
Cancel-Lock: sha1:gzVumRZ+vCEfJr74x2/fUzOCANM=
User-Agent: slrn/1.0.3 (OpenBSD)
 by: Jorgen Grahn - Mon, 28 Feb 2022 22:36 UTC

On Mon, 2022-02-28, ???? Tiib wrote:
> On Monday, 28 February 2022 at 00:35:56 UTC+2, das...@gmail.com wrote:
>> I have 3 variables used as interface variables between 2 threads. Thread A writes the variables, and Thread B reads them. Let me call them v1, v2, and v3.
>>
>> I buffer (or snapshot) them into local variables.
>>
>> Question: Do the local variables need to be declared volatile as well?
....

> Therefore your volatile usage is either pointless or platform-specific repair
> of defects in undisclosed MUTEX_BEGIN() and MUTEX_END().

Yeah, /that/ was my take on the question: that it's impossible to say
anything without knowing what MUTEX_BEGIN/END means. Normally a mutex
is an object which you lock or unlock, so these BEGIN/END things look
odd, and hint at a misunderstanding of the concepts.

/Jorgen

--
// Jorgen Grahn <grahn@ Oo o. . .
\X/ snipabacken.se> O o .

Re: Advanced (for me) Question About Keyword volatile

<20220228144043.99@kylheku.com>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=20608&group=comp.lang.c#20608

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: 480-992-...@kylheku.com (Kaz Kylheku)
Newsgroups: comp.lang.c
Subject: Re: Advanced (for me) Question About Keyword volatile
Date: Mon, 28 Feb 2022 22:45:12 -0000 (UTC)
Organization: A noiseless patient Spider
Lines: 30
Message-ID: <20220228144043.99@kylheku.com>
References: <4eddd378-e045-4242-bf9e-bc0efae0cea5n@googlegroups.com>
<9ae58a92-76d6-4aff-840f-b4d359ab695fn@googlegroups.com>
<slrnt1qjk8.1rfm.grahn+nntp@frailea.sa.invalid>
Injection-Date: Mon, 28 Feb 2022 22:45:12 -0000 (UTC)
Injection-Info: reader02.eternal-september.org; posting-host="df08c52b8280fc393c8d5f907716f696";
logging-data="12521"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18YRKk2JYlT5GZQTOvsaOLScALRkBC22l8="
User-Agent: slrn/1.0.3 (Linux)
Cancel-Lock: sha1:Et/gimBmTOp1RkGb7+R4zrPsnqA=
 by: Kaz Kylheku - Mon, 28 Feb 2022 22:45 UTC

On 2022-02-28, Jorgen Grahn <grahn+nntp@snipabacken.se> wrote:
> On Mon, 2022-02-28, ???? Tiib wrote:
>> On Monday, 28 February 2022 at 00:35:56 UTC+2, das...@gmail.com wrote:
>>> I have 3 variables used as interface variables between 2 threads. Thread A writes the variables, and Thread B reads them. Let me call them v1, v2, and v3.
>>>
>>> I buffer (or snapshot) them into local variables.
>>>
>>> Question: Do the local variables need to be declared volatile as well?
> ...
>
>> Therefore your volatile usage is either pointless or platform-specific repair
>> of defects in undisclosed MUTEX_BEGIN() and MUTEX_END().
>
> Yeah, /that/ was my take on the question: that it's impossible to say
> anything without knowing what MUTEX_BEGIN/END means. Normally a mutex
> is an object which you lock or unlock, so these BEGIN/END things look
> odd, and hint at a misunderstanding of the concepts.

Mutexes protect critial regions of code, which begin and end.

"Mutually exclusive execution belongs here; ends here."

Makes sense.

Rather, what is strange is the "mutex" naming metonymy: the object used
for ensuring mutual exclusion is called "mutual exclusion".

--
TXR Programming Language: http://nongnu.org/txr
Cygnal: Cygwin Native Application Library: http://kylheku.com/cygnal

Re: Advanced (for me) Question About Keyword volatile

<svkj9o$hqu$4@dont-email.me>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=20624&group=comp.lang.c#20624

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: Bonita.M...@gmail.com (Bonita Montero)
Newsgroups: comp.lang.c
Subject: Re: Advanced (for me) Question About Keyword volatile
Date: Tue, 1 Mar 2022 08:51:24 +0100
Organization: A noiseless patient Spider
Lines: 20
Message-ID: <svkj9o$hqu$4@dont-email.me>
References: <4eddd378-e045-4242-bf9e-bc0efae0cea5n@googlegroups.com>
<svh461$3jf$1@dont-email.me>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
Injection-Date: Tue, 1 Mar 2022 07:51:20 -0000 (UTC)
Injection-Info: reader02.eternal-september.org; posting-host="5810512e555e646a4ebb234d1b5db876";
logging-data="18270"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+jYFAOD4PLQloV2QgPzOFbpMggOX9WbaA="
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:91.0) Gecko/20100101
Thunderbird/91.6.1
Cancel-Lock: sha1:xx0CNPxCtJ/iPhOF/MKu89d7VYk=
In-Reply-To: <svh461$3jf$1@dont-email.me>
Content-Language: de-DE
 by: Bonita Montero - Tue, 1 Mar 2022 07:51 UTC

Am 28.02.2022 um 01:14 schrieb Chris M. Thomasson:
> On 2/27/2022 2:35 PM, das...@gmail.com wrote:
>> I have 3 variables used as interface variables between 2 threads.
>> Thread A writes the variables, and Thread B reads them.  Let me call
>> them v1, v2, and v3.
>>
>> I buffer (or snapshot) them into local variables.
>>
>> Question:  Do the local variables need to be declared volatile as well?
>
> The local variables are fine, and do not need to be atomic/volatile,
> ect... Btw, think about using C atomic's instead of volatile. You might
> be interested in a seqlock:
> https://en.wikipedia.org/wiki/Seqlock
> (read all)
> They are geared to a read-mostly, write rarely pattern.

Seqlocks don't make sense in user-space as they're lock-free and
a writer, having made the seq-counter odd, may be easily scheduled
away before making the seq-counter even again.

Re: Advanced (for me) Question About Keyword volatile

<svkl61$vca$1@dont-email.me>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=20625&group=comp.lang.c#20625

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: Bonita.M...@gmail.com (Bonita Montero)
Newsgroups: comp.lang.c
Subject: Re: Advanced (for me) Question About Keyword volatile
Date: Tue, 1 Mar 2022 09:23:33 +0100
Organization: A noiseless patient Spider
Lines: 39
Message-ID: <svkl61$vca$1@dont-email.me>
References: <4eddd378-e045-4242-bf9e-bc0efae0cea5n@googlegroups.com>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Tue, 1 Mar 2022 08:23:29 -0000 (UTC)
Injection-Info: reader02.eternal-september.org; posting-host="5810512e555e646a4ebb234d1b5db876";
logging-data="32138"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/kwPVEsqBsuRxjP1Vg+d2zHuSbpukBoBo="
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:91.0) Gecko/20100101
Thunderbird/91.6.1
Cancel-Lock: sha1:tDSxFBRc703cS4VlNqKoYoJ2VMw=
In-Reply-To: <4eddd378-e045-4242-bf9e-bc0efae0cea5n@googlegroups.com>
Content-Language: de-DE
 by: Bonita Montero - Tue, 1 Mar 2022 08:23 UTC

Am 27.02.2022 um 23:35 schrieb das...@gmail.com:
> I have 3 variables used as interface variables between 2 threads. Thread A writes the variables, and Thread B reads them. Let me call them v1, v2, and v3.
>
> I buffer (or snapshot) them into local variables.
>
> Question: Do the local variables need to be declared volatile as well?
>
> Thanks, Dave A.
>
> Code below.
>
> -----
>
> volatile int v1;
> volatile int v2;
> volatile int v3;
>
> void ThreadA(void) //Writes the variables.
> {
> //3 critical sections, but doesn't matter if ThreadB()
> //obtains values not obtained at exactly the same
> //time.
> ...
> MUTEX_BEGIN();
> v1 = expression1;
> MUTEX_END();
> ...
> MUTEX_BEGIN();
> v2 = expression2;
> MUTEX_END();
> ...
> MUTEX_BEGIN();
> v3 = expression3;
> MUTEX_END();
> }

If MUTEX_BEGIN() and MUTEX_END() include proper barriers
no volatile is needed.

Re: Advanced (for me) Question About Keyword volatile

<svm3e0$3gj$1@dont-email.me>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=20660&group=comp.lang.c#20660

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: chris.m....@gmail.com (Chris M. Thomasson)
Newsgroups: comp.lang.c
Subject: Re: Advanced (for me) Question About Keyword volatile
Date: Tue, 1 Mar 2022 13:32:46 -0800
Organization: A noiseless patient Spider
Lines: 24
Message-ID: <svm3e0$3gj$1@dont-email.me>
References: <4eddd378-e045-4242-bf9e-bc0efae0cea5n@googlegroups.com>
<svh461$3jf$1@dont-email.me> <svkj9o$hqu$4@dont-email.me>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
Injection-Date: Tue, 1 Mar 2022 21:32:48 -0000 (UTC)
Injection-Info: reader02.eternal-september.org; posting-host="2b6d42798312c94a7226d0c09ce4678f";
logging-data="3603"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18DCt9a8h2q7d9ox3b1hjpQED6X/cUlkhI="
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:91.0) Gecko/20100101
Thunderbird/91.6.1
Cancel-Lock: sha1:garLJQs6oegUjRR/MKoT2g04J0U=
In-Reply-To: <svkj9o$hqu$4@dont-email.me>
Content-Language: en-US
 by: Chris M. Thomasson - Tue, 1 Mar 2022 21:32 UTC

On 2/28/2022 11:51 PM, Bonita Montero wrote:
> Am 28.02.2022 um 01:14 schrieb Chris M. Thomasson:
>> On 2/27/2022 2:35 PM, das...@gmail.com wrote:
>>> I have 3 variables used as interface variables between 2 threads.
>>> Thread A writes the variables, and Thread B reads them.  Let me call
>>> them v1, v2, and v3.
>>>
>>> I buffer (or snapshot) them into local variables.
>>>
>>> Question:  Do the local variables need to be declared volatile as well?
>>
>> The local variables are fine, and do not need to be atomic/volatile,
>> ect... Btw, think about using C atomic's instead of volatile. You
>> might be interested in a seqlock:
>> https://en.wikipedia.org/wiki/Seqlock
>> (read all)
>> They are geared to a read-mostly, write rarely pattern.
>
> Seqlocks don't make sense in user-space as they're lock-free and
> a writer, having made the seq-counter odd, may be easily scheduled
> away before making the seq-counter even again.

Huh? The writers use a mutex. So, how lock-free is a writer? For some
reason, I don't think you have ever used one.

Re: Advanced (for me) Question About Keyword volatile

<svmp9f$hpc$1@dont-email.me>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=20661&group=comp.lang.c#20661

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: Bonita.M...@gmail.com (Bonita Montero)
Newsgroups: comp.lang.c
Subject: Re: Advanced (for me) Question About Keyword volatile
Date: Wed, 2 Mar 2022 04:45:56 +0100
Organization: A noiseless patient Spider
Lines: 29
Message-ID: <svmp9f$hpc$1@dont-email.me>
References: <4eddd378-e045-4242-bf9e-bc0efae0cea5n@googlegroups.com>
<svh461$3jf$1@dont-email.me> <svkj9o$hqu$4@dont-email.me>
<svm3e0$3gj$1@dont-email.me>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
Injection-Date: Wed, 2 Mar 2022 03:45:51 -0000 (UTC)
Injection-Info: reader02.eternal-september.org; posting-host="267f58128df590709f4eff4ce2840dfa";
logging-data="18220"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+bLyk7nElKiS8wi+duEk7BLzrYu4kagWI="
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:91.0) Gecko/20100101
Thunderbird/91.6.1
Cancel-Lock: sha1:5m1p5YcsQZmhtSFTdDt1XqtkAfI=
In-Reply-To: <svm3e0$3gj$1@dont-email.me>
Content-Language: de-DE
 by: Bonita Montero - Wed, 2 Mar 2022 03:45 UTC

Am 01.03.2022 um 22:32 schrieb Chris M. Thomasson:
> On 2/28/2022 11:51 PM, Bonita Montero wrote:
>> Am 28.02.2022 um 01:14 schrieb Chris M. Thomasson:
>>> On 2/27/2022 2:35 PM, das...@gmail.com wrote:
>>>> I have 3 variables used as interface variables between 2 threads.
>>>> Thread A writes the variables, and Thread B reads them.  Let me call
>>>> them v1, v2, and v3.
>>>>
>>>> I buffer (or snapshot) them into local variables.
>>>>
>>>> Question:  Do the local variables need to be declared volatile as well?
>>>
>>> The local variables are fine, and do not need to be atomic/volatile,
>>> ect... Btw, think about using C atomic's instead of volatile. You
>>> might be interested in a seqlock:
>>> https://en.wikipedia.org/wiki/Seqlock
>>> (read all)
>>> They are geared to a read-mostly, write rarely pattern.
>>
>> Seqlocks don't make sense in user-space as they're lock-free and
>> a writer, having made the seq-counter odd, may be easily scheduled
>> away before making the seq-counter even again.
>
> Huh? The writers use a mutex. So, how lock-free is a writer?
> For some reason, I don't think you have ever used one.

Seqlocks need disabling the scheduler on a core while writing
that a writer can't be scheduled away. That's not possible in
user-mode.

Re: Advanced (for me) Question About Keyword volatile

<svmppj$l0t$1@dont-email.me>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=20662&group=comp.lang.c#20662

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: chris.m....@gmail.com (Chris M. Thomasson)
Newsgroups: comp.lang.c
Subject: Re: Advanced (for me) Question About Keyword volatile
Date: Tue, 1 Mar 2022 19:54:24 -0800
Organization: A noiseless patient Spider
Lines: 40
Message-ID: <svmppj$l0t$1@dont-email.me>
References: <4eddd378-e045-4242-bf9e-bc0efae0cea5n@googlegroups.com>
<svh461$3jf$1@dont-email.me> <svkj9o$hqu$4@dont-email.me>
<svm3e0$3gj$1@dont-email.me> <svmp9f$hpc$1@dont-email.me>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
Injection-Date: Wed, 2 Mar 2022 03:54:27 -0000 (UTC)
Injection-Info: reader02.eternal-september.org; posting-host="d4a417dfd5e5fa43753e81c21b04ad49";
logging-data="21533"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19lXisi5DziQXn7TAXYMuLB52ApDeERKVI="
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:91.0) Gecko/20100101
Thunderbird/91.6.1
Cancel-Lock: sha1:tOntr0Wrhx3tyvTQv1dskgsfQqI=
In-Reply-To: <svmp9f$hpc$1@dont-email.me>
Content-Language: en-US
 by: Chris M. Thomasson - Wed, 2 Mar 2022 03:54 UTC

On 3/1/2022 7:45 PM, Bonita Montero wrote:
> Am 01.03.2022 um 22:32 schrieb Chris M. Thomasson:
>> On 2/28/2022 11:51 PM, Bonita Montero wrote:
>>> Am 28.02.2022 um 01:14 schrieb Chris M. Thomasson:
>>>> On 2/27/2022 2:35 PM, das...@gmail.com wrote:
>>>>> I have 3 variables used as interface variables between 2 threads.
>>>>> Thread A writes the variables, and Thread B reads them.  Let me
>>>>> call them v1, v2, and v3.
>>>>>
>>>>> I buffer (or snapshot) them into local variables.
>>>>>
>>>>> Question:  Do the local variables need to be declared volatile as
>>>>> well?
>>>>
>>>> The local variables are fine, and do not need to be atomic/volatile,
>>>> ect... Btw, think about using C atomic's instead of volatile. You
>>>> might be interested in a seqlock:
>>>> https://en.wikipedia.org/wiki/Seqlock
>>>> (read all)
>>>> They are geared to a read-mostly, write rarely pattern.
>>>
>>> Seqlocks don't make sense in user-space as they're lock-free and
>>> a writer, having made the seq-counter odd, may be easily scheduled
>>> away before making the seq-counter even again.
>>
>> Huh? The writers use a mutex. So, how lock-free is a writer?
>> For some reason, I don't think you have ever used one.
>
> Seqlocks need disabling the scheduler on a core while writing
> that a writer can't be scheduled away. That's not possible in
> user-mode.

Huh? Wow. This basically confirms that you have never used a seqlock in
user land. Remember that the writer uses a normal mutex. Now, a friend
of mine created a really neat mutation of a seqlock:

https://www.1024cores.net/home/lock-free-algorithms/reader-writer-problem/improved-lock-free-seqlock

Implementing a seqlock is tricky wrt proper memory visibility, but it
can be done in 100% pure C11.

Re: Advanced (for me) Question About Keyword volatile

<svmqr5$qj0$1@dont-email.me>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=20663&group=comp.lang.c#20663

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: Bonita.M...@gmail.com (Bonita Montero)
Newsgroups: comp.lang.c
Subject: Re: Advanced (for me) Question About Keyword volatile
Date: Wed, 2 Mar 2022 05:12:26 +0100
Organization: A noiseless patient Spider
Lines: 40
Message-ID: <svmqr5$qj0$1@dont-email.me>
References: <4eddd378-e045-4242-bf9e-bc0efae0cea5n@googlegroups.com>
<svh461$3jf$1@dont-email.me> <svkj9o$hqu$4@dont-email.me>
<svm3e0$3gj$1@dont-email.me> <svmp9f$hpc$1@dont-email.me>
<svmppj$l0t$1@dont-email.me>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
Injection-Date: Wed, 2 Mar 2022 04:12:21 -0000 (UTC)
Injection-Info: reader02.eternal-september.org; posting-host="267f58128df590709f4eff4ce2840dfa";
logging-data="27232"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19NEDsfbtbp6O8kXkZJEKi74m1eYcaBJBE="
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:91.0) Gecko/20100101
Thunderbird/91.6.1
Cancel-Lock: sha1:UruhOFpgpm6m82Jh1h+l7uM9B+s=
In-Reply-To: <svmppj$l0t$1@dont-email.me>
Content-Language: de-DE
 by: Bonita Montero - Wed, 2 Mar 2022 04:12 UTC

Am 02.03.2022 um 04:54 schrieb Chris M. Thomasson:
> On 3/1/2022 7:45 PM, Bonita Montero wrote:
>> Am 01.03.2022 um 22:32 schrieb Chris M. Thomasson:
>>> On 2/28/2022 11:51 PM, Bonita Montero wrote:
>>>> Am 28.02.2022 um 01:14 schrieb Chris M. Thomasson:
>>>>> On 2/27/2022 2:35 PM, das...@gmail.com wrote:
>>>>>> I have 3 variables used as interface variables between 2 threads.
>>>>>> Thread A writes the variables, and Thread B reads them.  Let me
>>>>>> call them v1, v2, and v3.
>>>>>>
>>>>>> I buffer (or snapshot) them into local variables.
>>>>>>
>>>>>> Question:  Do the local variables need to be declared volatile as
>>>>>> well?
>>>>>
>>>>> The local variables are fine, and do not need to be
>>>>> atomic/volatile, ect... Btw, think about using C atomic's instead
>>>>> of volatile. You might be interested in a seqlock:
>>>>> https://en.wikipedia.org/wiki/Seqlock
>>>>> (read all)
>>>>> They are geared to a read-mostly, write rarely pattern.
>>>>
>>>> Seqlocks don't make sense in user-space as they're lock-free and
>>>> a writer, having made the seq-counter odd, may be easily scheduled
>>>> away before making the seq-counter even again.
>>>
>>> Huh? The writers use a mutex. So, how lock-free is a writer?
>>> For some reason, I don't think you have ever used one.
>>
>> Seqlocks need disabling the scheduler on a core while writing
>> that a writer can't be scheduled away. That's not possible in
>> user-mode.
>
> Huh? Wow. This basically confirms that you have never used a seqlock in
> user land. Remember that the writer uses a normal mutex. Now, a friend
> of mine created a really neat mutation of a seqlock:

No, readers and writers spin.
Otherwise you don't have a seq-lock but sth. different.
Look how it is implemented in the Linux kernel.

Re: Advanced (for me) Question About Keyword volatile

<svmr4q$sh0$2@dont-email.me>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=20664&group=comp.lang.c#20664

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: chris.m....@gmail.com (Chris M. Thomasson)
Newsgroups: comp.lang.c
Subject: Re: Advanced (for me) Question About Keyword volatile
Date: Tue, 1 Mar 2022 20:17:29 -0800
Organization: A noiseless patient Spider
Lines: 44
Message-ID: <svmr4q$sh0$2@dont-email.me>
References: <4eddd378-e045-4242-bf9e-bc0efae0cea5n@googlegroups.com>
<svh461$3jf$1@dont-email.me> <svkj9o$hqu$4@dont-email.me>
<svm3e0$3gj$1@dont-email.me> <svmp9f$hpc$1@dont-email.me>
<svmppj$l0t$1@dont-email.me> <svmqr5$qj0$1@dont-email.me>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
Injection-Date: Wed, 2 Mar 2022 04:17:30 -0000 (UTC)
Injection-Info: reader02.eternal-september.org; posting-host="d4a417dfd5e5fa43753e81c21b04ad49";
logging-data="29216"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/TubV5YQxL+tBltB7YxVKI+WvW3Vo+eQg="
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:91.0) Gecko/20100101
Thunderbird/91.6.1
Cancel-Lock: sha1:KVLeaXI4l/9qSfsH1o2+LKVQM2g=
In-Reply-To: <svmqr5$qj0$1@dont-email.me>
Content-Language: en-US
 by: Chris M. Thomasson - Wed, 2 Mar 2022 04:17 UTC

On 3/1/2022 8:12 PM, Bonita Montero wrote:
> Am 02.03.2022 um 04:54 schrieb Chris M. Thomasson:
>> On 3/1/2022 7:45 PM, Bonita Montero wrote:
>>> Am 01.03.2022 um 22:32 schrieb Chris M. Thomasson:
>>>> On 2/28/2022 11:51 PM, Bonita Montero wrote:
>>>>> Am 28.02.2022 um 01:14 schrieb Chris M. Thomasson:
>>>>>> On 2/27/2022 2:35 PM, das...@gmail.com wrote:
>>>>>>> I have 3 variables used as interface variables between 2 threads.
>>>>>>> Thread A writes the variables, and Thread B reads them.  Let me
>>>>>>> call them v1, v2, and v3.
>>>>>>>
>>>>>>> I buffer (or snapshot) them into local variables.
>>>>>>>
>>>>>>> Question:  Do the local variables need to be declared volatile as
>>>>>>> well?
>>>>>>
>>>>>> The local variables are fine, and do not need to be
>>>>>> atomic/volatile, ect... Btw, think about using C atomic's instead
>>>>>> of volatile. You might be interested in a seqlock:
>>>>>> https://en.wikipedia.org/wiki/Seqlock
>>>>>> (read all)
>>>>>> They are geared to a read-mostly, write rarely pattern.
>>>>>
>>>>> Seqlocks don't make sense in user-space as they're lock-free and
>>>>> a writer, having made the seq-counter odd, may be easily scheduled
>>>>> away before making the seq-counter even again.
>>>>
>>>> Huh? The writers use a mutex. So, how lock-free is a writer?
>>>> For some reason, I don't think you have ever used one.
>>>
>>> Seqlocks need disabling the scheduler on a core while writing
>>> that a writer can't be scheduled away. That's not possible in
>>> user-mode.
>>
>> Huh? Wow. This basically confirms that you have never used a seqlock
>> in user land. Remember that the writer uses a normal mutex. Now, a
>> friend of mine created a really neat mutation of a seqlock:
>
> No, readers and writers spin.
> Otherwise you don't have a seq-lock but sth. different.
> Look how it is implemented in the Linux kernel.

Writers never spin. They use a lock. Read about the algorithm. Read it
again, and one more time.

Re: Advanced (for me) Question About Keyword volatile

<svmrp4$vlj$1@dont-email.me>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=20665&group=comp.lang.c#20665

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!paganini.bofh.team!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: Bonita.M...@gmail.com (Bonita Montero)
Newsgroups: comp.lang.c
Subject: Re: Advanced (for me) Question About Keyword volatile
Date: Wed, 2 Mar 2022 05:28:25 +0100
Organization: A noiseless patient Spider
Lines: 53
Message-ID: <svmrp4$vlj$1@dont-email.me>
References: <4eddd378-e045-4242-bf9e-bc0efae0cea5n@googlegroups.com>
<svh461$3jf$1@dont-email.me> <svkj9o$hqu$4@dont-email.me>
<svm3e0$3gj$1@dont-email.me> <svmp9f$hpc$1@dont-email.me>
<svmppj$l0t$1@dont-email.me> <svmqr5$qj0$1@dont-email.me>
<svmr4q$sh0$2@dont-email.me>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
Injection-Date: Wed, 2 Mar 2022 04:28:20 -0000 (UTC)
Injection-Info: reader02.eternal-september.org; posting-host="267f58128df590709f4eff4ce2840dfa";
logging-data="32435"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/DTNatYtizxvPjChEhQ6dzLUu7kKLxJok="
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:91.0) Gecko/20100101
Thunderbird/91.6.1
Cancel-Lock: sha1:8jp/9IQnRp5MWuuHtOwbT1RLuVI=
In-Reply-To: <svmr4q$sh0$2@dont-email.me>
Content-Language: de-DE
 by: Bonita Montero - Wed, 2 Mar 2022 04:28 UTC

Am 02.03.2022 um 05:17 schrieb Chris M. Thomasson:
> On 3/1/2022 8:12 PM, Bonita Montero wrote:
>> Am 02.03.2022 um 04:54 schrieb Chris M. Thomasson:
>>> On 3/1/2022 7:45 PM, Bonita Montero wrote:
>>>> Am 01.03.2022 um 22:32 schrieb Chris M. Thomasson:
>>>>> On 2/28/2022 11:51 PM, Bonita Montero wrote:
>>>>>> Am 28.02.2022 um 01:14 schrieb Chris M. Thomasson:
>>>>>>> On 2/27/2022 2:35 PM, das...@gmail.com wrote:
>>>>>>>> I have 3 variables used as interface variables between 2
>>>>>>>> threads. Thread A writes the variables, and Thread B reads
>>>>>>>> them.  Let me call them v1, v2, and v3.
>>>>>>>>
>>>>>>>> I buffer (or snapshot) them into local variables.
>>>>>>>>
>>>>>>>> Question:  Do the local variables need to be declared volatile
>>>>>>>> as well?
>>>>>>>
>>>>>>> The local variables are fine, and do not need to be
>>>>>>> atomic/volatile, ect... Btw, think about using C atomic's instead
>>>>>>> of volatile. You might be interested in a seqlock:
>>>>>>> https://en.wikipedia.org/wiki/Seqlock
>>>>>>> (read all)
>>>>>>> They are geared to a read-mostly, write rarely pattern.
>>>>>>
>>>>>> Seqlocks don't make sense in user-space as they're lock-free and
>>>>>> a writer, having made the seq-counter odd, may be easily scheduled
>>>>>> away before making the seq-counter even again.
>>>>>
>>>>> Huh? The writers use a mutex. So, how lock-free is a writer?
>>>>> For some reason, I don't think you have ever used one.
>>>>
>>>> Seqlocks need disabling the scheduler on a core while writing
>>>> that a writer can't be scheduled away. That's not possible in
>>>> user-mode.
>>>
>>> Huh? Wow. This basically confirms that you have never used a seqlock
>>> in user land. Remember that the writer uses a normal mutex. Now, a
>>> friend of mine created a really neat mutation of a seqlock:
>>
>> No, readers and writers spin.
>> Otherwise you don't have a seq-lock but sth. different.
>> Look how it is implemented in the Linux kernel.
>
> Writers never spin. They use a lock. Read about the algorithm. Read it
> again, and one more time.

With seqlocks like in the kernel writer always spin.
Seqlocks inside the kernel never use a mutex.

And this seqlock-"implementation" on 1024 cores ist stupid.
With this implementation readers could spin for a long time
when a writer is scheduled away. That's not tolerable.

Re: Advanced (for me) Question About Keyword volatile

<svmrra$tr$1@dont-email.me>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=20666&group=comp.lang.c#20666

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: chris.m....@gmail.com (Chris M. Thomasson)
Newsgroups: comp.lang.c
Subject: Re: Advanced (for me) Question About Keyword volatile
Date: Tue, 1 Mar 2022 20:29:27 -0800
Organization: A noiseless patient Spider
Lines: 88
Message-ID: <svmrra$tr$1@dont-email.me>
References: <4eddd378-e045-4242-bf9e-bc0efae0cea5n@googlegroups.com>
<svh461$3jf$1@dont-email.me> <svkj9o$hqu$4@dont-email.me>
<svm3e0$3gj$1@dont-email.me> <svmp9f$hpc$1@dont-email.me>
<svmppj$l0t$1@dont-email.me> <svmqr5$qj0$1@dont-email.me>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
Injection-Date: Wed, 2 Mar 2022 04:29:30 -0000 (UTC)
Injection-Info: reader02.eternal-september.org; posting-host="d4a417dfd5e5fa43753e81c21b04ad49";
logging-data="955"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/jj1qpctR3LiKxjofkwjvb2X8lEGQTstY="
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:91.0) Gecko/20100101
Thunderbird/91.6.1
Cancel-Lock: sha1:MVNHLM/tOBeri9vw3M1XD+bphpk=
In-Reply-To: <svmqr5$qj0$1@dont-email.me>
Content-Language: en-US
 by: Chris M. Thomasson - Wed, 2 Mar 2022 04:29 UTC

On 3/1/2022 8:12 PM, Bonita Montero wrote:
> Am 02.03.2022 um 04:54 schrieb Chris M. Thomasson:
>> On 3/1/2022 7:45 PM, Bonita Montero wrote:
>>> Am 01.03.2022 um 22:32 schrieb Chris M. Thomasson:
>>>> On 2/28/2022 11:51 PM, Bonita Montero wrote:
>>>>> Am 28.02.2022 um 01:14 schrieb Chris M. Thomasson:
>>>>>> On 2/27/2022 2:35 PM, das...@gmail.com wrote:
>>>>>>> I have 3 variables used as interface variables between 2 threads.
>>>>>>> Thread A writes the variables, and Thread B reads them.  Let me
>>>>>>> call them v1, v2, and v3.
>>>>>>>
>>>>>>> I buffer (or snapshot) them into local variables.
>>>>>>>
>>>>>>> Question:  Do the local variables need to be declared volatile as
>>>>>>> well?
>>>>>>
>>>>>> The local variables are fine, and do not need to be
>>>>>> atomic/volatile, ect... Btw, think about using C atomic's instead
>>>>>> of volatile. You might be interested in a seqlock:
>>>>>> https://en.wikipedia.org/wiki/Seqlock
>>>>>> (read all)
>>>>>> They are geared to a read-mostly, write rarely pattern.
>>>>>
>>>>> Seqlocks don't make sense in user-space as they're lock-free and
>>>>> a writer, having made the seq-counter odd, may be easily scheduled
>>>>> away before making the seq-counter even again.
>>>>
>>>> Huh? The writers use a mutex. So, how lock-free is a writer?
>>>> For some reason, I don't think you have ever used one.
>>>
>>> Seqlocks need disabling the scheduler on a core while writing
>>> that a writer can't be scheduled away. That's not possible in
>>> user-mode.
>>
>> Huh? Wow. This basically confirms that you have never used a seqlock
>> in user land. Remember that the writer uses a normal mutex. Now, a
>> friend of mine created a really neat mutation of a seqlock:
>
> No, readers and writers spin.
> Otherwise you don't have a seq-lock but sth. different.
> Look how it is implemented in the Linux kernel.

The basic seqlock minus the tricky membars:

// quick and crude pseudo-code

struct state { int a = 0; }
mutex g_lock;
atomic_unsigned g_ver = 0;

state g_state;

// writers
lock(g_lock);
++ver;

++g_state.a;

++ver;
unlock(g_lock);

// readers
state lstate;

for (;;)
{ unsigned ver0 = g_ver;

lstate = g_state;

unsigned ver1 = g_ver;

if ((! (ver0 & 1)) && (ver0 == ver1))
{
break;
}

// A reader spun! Humm...
// yield, backoff, do something else
}

The pattern is read-mostly, write-rarely. Fast reads, slow writes. It
works in user-land.

Re: Advanced (for me) Question About Keyword volatile

<svmsfh$49c$1@dont-email.me>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=20667&group=comp.lang.c#20667

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: Bonita.M...@gmail.com (Bonita Montero)
Newsgroups: comp.lang.c
Subject: Re: Advanced (for me) Question About Keyword volatile
Date: Wed, 2 Mar 2022 05:40:21 +0100
Organization: A noiseless patient Spider
Lines: 98
Message-ID: <svmsfh$49c$1@dont-email.me>
References: <4eddd378-e045-4242-bf9e-bc0efae0cea5n@googlegroups.com>
<svh461$3jf$1@dont-email.me> <svkj9o$hqu$4@dont-email.me>
<svm3e0$3gj$1@dont-email.me> <svmp9f$hpc$1@dont-email.me>
<svmppj$l0t$1@dont-email.me> <svmqr5$qj0$1@dont-email.me>
<svmrra$tr$1@dont-email.me>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
Injection-Date: Wed, 2 Mar 2022 04:40:17 -0000 (UTC)
Injection-Info: reader02.eternal-september.org; posting-host="267f58128df590709f4eff4ce2840dfa";
logging-data="4396"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/4f5zGG9CjzXjsy/eyNOwYdyukpmrnyYg="
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:91.0) Gecko/20100101
Thunderbird/91.6.1
Cancel-Lock: sha1:DuOzs2u8HaZ+Ad2RxbmBfAchG6s=
In-Reply-To: <svmrra$tr$1@dont-email.me>
Content-Language: de-DE
 by: Bonita Montero - Wed, 2 Mar 2022 04:40 UTC

Am 02.03.2022 um 05:29 schrieb Chris M. Thomasson:
> On 3/1/2022 8:12 PM, Bonita Montero wrote:
>> Am 02.03.2022 um 04:54 schrieb Chris M. Thomasson:
>>> On 3/1/2022 7:45 PM, Bonita Montero wrote:
>>>> Am 01.03.2022 um 22:32 schrieb Chris M. Thomasson:
>>>>> On 2/28/2022 11:51 PM, Bonita Montero wrote:
>>>>>> Am 28.02.2022 um 01:14 schrieb Chris M. Thomasson:
>>>>>>> On 2/27/2022 2:35 PM, das...@gmail.com wrote:
>>>>>>>> I have 3 variables used as interface variables between 2
>>>>>>>> threads. Thread A writes the variables, and Thread B reads
>>>>>>>> them.  Let me call them v1, v2, and v3.
>>>>>>>>
>>>>>>>> I buffer (or snapshot) them into local variables.
>>>>>>>>
>>>>>>>> Question:  Do the local variables need to be declared volatile
>>>>>>>> as well?
>>>>>>>
>>>>>>> The local variables are fine, and do not need to be
>>>>>>> atomic/volatile, ect... Btw, think about using C atomic's instead
>>>>>>> of volatile. You might be interested in a seqlock:
>>>>>>> https://en.wikipedia.org/wiki/Seqlock
>>>>>>> (read all)
>>>>>>> They are geared to a read-mostly, write rarely pattern.
>>>>>>
>>>>>> Seqlocks don't make sense in user-space as they're lock-free and
>>>>>> a writer, having made the seq-counter odd, may be easily scheduled
>>>>>> away before making the seq-counter even again.
>>>>>
>>>>> Huh? The writers use a mutex. So, how lock-free is a writer?
>>>>> For some reason, I don't think you have ever used one.
>>>>
>>>> Seqlocks need disabling the scheduler on a core while writing
>>>> that a writer can't be scheduled away. That's not possible in
>>>> user-mode.
>>>
>>> Huh? Wow. This basically confirms that you have never used a seqlock
>>> in user land. Remember that the writer uses a normal mutex. Now, a
>>> friend of mine created a really neat mutation of a seqlock:
>>
>> No, readers and writers spin.
>> Otherwise you don't have a seq-lock but sth. different.
>> Look how it is implemented in the Linux kernel.
>
>
> The basic seqlock minus the tricky membars:
>
> // quick and crude pseudo-code
>
> struct state { int a = 0; }
> mutex g_lock;
> atomic_unsigned g_ver = 0;
>
> state g_state;
>
> // writers
> lock(g_lock);
>   ++ver;
>
>     ++g_state.a;
>
>   ++ver;
> unlock(g_lock);
>
>
> // readers
> state lstate;
>
> for (;;)
> {
>   unsigned ver0 = g_ver;
>
>     lstate = g_state;
>
>   unsigned ver1 = g_ver;
>
>
>   if ((! (ver0 & 1)) && (ver0 == ver1))
>   {
>      break;
>   }
>
>
>   // A reader spun! Humm...
>   // yield, backoff, do something else
> }
>
>
> The pattern is read-mostly, write-rarely. Fast reads, slow writes. It
> works in user-land.

Boy, you're so ultimately studpid.

Readers could spin for a long time when whe writer is scheduled
away. So the approach of 1024 cores is not tolerable in userspace
and seqlocks only make sense in kernel space where the writer could
disable scheduling while spinning of modifying.

Re: Advanced (for me) Question About Keyword volatile

<svmshk$594$1@dont-email.me>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=20668&group=comp.lang.c#20668

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: chris.m....@gmail.com (Chris M. Thomasson)
Newsgroups: comp.lang.c
Subject: Re: Advanced (for me) Question About Keyword volatile
Date: Tue, 1 Mar 2022 20:41:21 -0800
Organization: A noiseless patient Spider
Lines: 62
Message-ID: <svmshk$594$1@dont-email.me>
References: <4eddd378-e045-4242-bf9e-bc0efae0cea5n@googlegroups.com>
<svh461$3jf$1@dont-email.me> <svkj9o$hqu$4@dont-email.me>
<svm3e0$3gj$1@dont-email.me> <svmp9f$hpc$1@dont-email.me>
<svmppj$l0t$1@dont-email.me> <svmqr5$qj0$1@dont-email.me>
<svmr4q$sh0$2@dont-email.me> <svmrp4$vlj$1@dont-email.me>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
Injection-Date: Wed, 2 Mar 2022 04:41:24 -0000 (UTC)
Injection-Info: reader02.eternal-september.org; posting-host="d4a417dfd5e5fa43753e81c21b04ad49";
logging-data="5412"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19NOtm9PBAOtoqNvWaApOMfKgBCpUj9ZCM="
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:91.0) Gecko/20100101
Thunderbird/91.6.1
Cancel-Lock: sha1:pKcIKiWYyCh6tjiEpHt9N8w3jqk=
In-Reply-To: <svmrp4$vlj$1@dont-email.me>
Content-Language: en-US
 by: Chris M. Thomasson - Wed, 2 Mar 2022 04:41 UTC

On 3/1/2022 8:28 PM, Bonita Montero wrote:
> Am 02.03.2022 um 05:17 schrieb Chris M. Thomasson:
>> On 3/1/2022 8:12 PM, Bonita Montero wrote:
>>> Am 02.03.2022 um 04:54 schrieb Chris M. Thomasson:
>>>> On 3/1/2022 7:45 PM, Bonita Montero wrote:
>>>>> Am 01.03.2022 um 22:32 schrieb Chris M. Thomasson:
>>>>>> On 2/28/2022 11:51 PM, Bonita Montero wrote:
>>>>>>> Am 28.02.2022 um 01:14 schrieb Chris M. Thomasson:
>>>>>>>> On 2/27/2022 2:35 PM, das...@gmail.com wrote:
>>>>>>>>> I have 3 variables used as interface variables between 2
>>>>>>>>> threads. Thread A writes the variables, and Thread B reads
>>>>>>>>> them.  Let me call them v1, v2, and v3.
>>>>>>>>>
>>>>>>>>> I buffer (or snapshot) them into local variables.
>>>>>>>>>
>>>>>>>>> Question:  Do the local variables need to be declared volatile
>>>>>>>>> as well?
>>>>>>>>
>>>>>>>> The local variables are fine, and do not need to be
>>>>>>>> atomic/volatile, ect... Btw, think about using C atomic's
>>>>>>>> instead of volatile. You might be interested in a seqlock:
>>>>>>>> https://en.wikipedia.org/wiki/Seqlock
>>>>>>>> (read all)
>>>>>>>> They are geared to a read-mostly, write rarely pattern.
>>>>>>>
>>>>>>> Seqlocks don't make sense in user-space as they're lock-free and
>>>>>>> a writer, having made the seq-counter odd, may be easily scheduled
>>>>>>> away before making the seq-counter even again.
>>>>>>
>>>>>> Huh? The writers use a mutex. So, how lock-free is a writer?
>>>>>> For some reason, I don't think you have ever used one.
>>>>>
>>>>> Seqlocks need disabling the scheduler on a core while writing
>>>>> that a writer can't be scheduled away. That's not possible in
>>>>> user-mode.
>>>>
>>>> Huh? Wow. This basically confirms that you have never used a seqlock
>>>> in user land. Remember that the writer uses a normal mutex. Now, a
>>>> friend of mine created a really neat mutation of a seqlock:
>>>
>>> No, readers and writers spin.
>>> Otherwise you don't have a seq-lock but sth. different.
>>> Look how it is implemented in the Linux kernel.
>>
>> Writers never spin. They use a lock. Read about the algorithm. Read it
>> again, and one more time.
>
> With seqlocks like in the kernel writer always spin.
> Seqlocks inside the kernel never use a mutex.
>
> And this seqlock-"implementation" on 1024 cores ist stupid.

You really think so? Wow.

> With this implementation readers could spin for a long time
> when a writer is scheduled away. That's not tolerable.

The readers can choose to spin, or do something else. Traditional
Seqlocks are really great in read-mostly, write rarely scenarios, yes in
user space. Btw, my friends impl heavily reduces reader spins if a lot
of writer activity suddenly occurs by heavily amortizing things. Keep in
mind of the usage pattern.

Re: Advanced (for me) Question About Keyword volatile

<svmsn2$570$1@dont-email.me>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=20670&group=comp.lang.c#20670

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: Bonita.M...@gmail.com (Bonita Montero)
Newsgroups: comp.lang.c
Subject: Re: Advanced (for me) Question About Keyword volatile
Date: Wed, 2 Mar 2022 05:44:23 +0100
Organization: A noiseless patient Spider
Lines: 63
Message-ID: <svmsn2$570$1@dont-email.me>
References: <4eddd378-e045-4242-bf9e-bc0efae0cea5n@googlegroups.com>
<svh461$3jf$1@dont-email.me> <svkj9o$hqu$4@dont-email.me>
<svm3e0$3gj$1@dont-email.me> <svmp9f$hpc$1@dont-email.me>
<svmppj$l0t$1@dont-email.me> <svmqr5$qj0$1@dont-email.me>
<svmr4q$sh0$2@dont-email.me> <svmrp4$vlj$1@dont-email.me>
<svmshk$594$1@dont-email.me>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
Injection-Date: Wed, 2 Mar 2022 04:44:18 -0000 (UTC)
Injection-Info: reader02.eternal-september.org; posting-host="267f58128df590709f4eff4ce2840dfa";
logging-data="5344"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/XEV/a98fXkWCMhI9TVSCYOlCSnEMIrtE="
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:91.0) Gecko/20100101
Thunderbird/91.6.1
Cancel-Lock: sha1:09TYJISF5CLqwceAqAbWJVmcMDk=
In-Reply-To: <svmshk$594$1@dont-email.me>
Content-Language: de-DE
 by: Bonita Montero - Wed, 2 Mar 2022 04:44 UTC

Am 02.03.2022 um 05:41 schrieb Chris M. Thomasson:
> On 3/1/2022 8:28 PM, Bonita Montero wrote:
>> Am 02.03.2022 um 05:17 schrieb Chris M. Thomasson:
>>> On 3/1/2022 8:12 PM, Bonita Montero wrote:
>>>> Am 02.03.2022 um 04:54 schrieb Chris M. Thomasson:
>>>>> On 3/1/2022 7:45 PM, Bonita Montero wrote:
>>>>>> Am 01.03.2022 um 22:32 schrieb Chris M. Thomasson:
>>>>>>> On 2/28/2022 11:51 PM, Bonita Montero wrote:
>>>>>>>> Am 28.02.2022 um 01:14 schrieb Chris M. Thomasson:
>>>>>>>>> On 2/27/2022 2:35 PM, das...@gmail.com wrote:
>>>>>>>>>> I have 3 variables used as interface variables between 2
>>>>>>>>>> threads. Thread A writes the variables, and Thread B reads
>>>>>>>>>> them.  Let me call them v1, v2, and v3.
>>>>>>>>>>
>>>>>>>>>> I buffer (or snapshot) them into local variables.
>>>>>>>>>>
>>>>>>>>>> Question:  Do the local variables need to be declared volatile
>>>>>>>>>> as well?
>>>>>>>>>
>>>>>>>>> The local variables are fine, and do not need to be
>>>>>>>>> atomic/volatile, ect... Btw, think about using C atomic's
>>>>>>>>> instead of volatile. You might be interested in a seqlock:
>>>>>>>>> https://en.wikipedia.org/wiki/Seqlock
>>>>>>>>> (read all)
>>>>>>>>> They are geared to a read-mostly, write rarely pattern.
>>>>>>>>
>>>>>>>> Seqlocks don't make sense in user-space as they're lock-free and
>>>>>>>> a writer, having made the seq-counter odd, may be easily scheduled
>>>>>>>> away before making the seq-counter even again.
>>>>>>>
>>>>>>> Huh? The writers use a mutex. So, how lock-free is a writer?
>>>>>>> For some reason, I don't think you have ever used one.
>>>>>>
>>>>>> Seqlocks need disabling the scheduler on a core while writing
>>>>>> that a writer can't be scheduled away. That's not possible in
>>>>>> user-mode.
>>>>>
>>>>> Huh? Wow. This basically confirms that you have never used a
>>>>> seqlock in user land. Remember that the writer uses a normal mutex.
>>>>> Now, a friend of mine created a really neat mutation of a seqlock:
>>>>
>>>> No, readers and writers spin.
>>>> Otherwise you don't have a seq-lock but sth. different.
>>>> Look how it is implemented in the Linux kernel.
>>>
>>> Writers never spin. They use a lock. Read about the algorithm. Read
>>> it again, and one more time.
>>
>> With seqlocks like in the kernel writer always spin.
>> Seqlocks inside the kernel never use a mutex.
>>
>> And this seqlock-"implementation" on 1024 cores ist stupid.
>
> You really think so? Wow.

Yes, with that implementaiton a writer could be scheduled away
and a reader could spin for a long time.
Seqlocks inside the kernel don't use mutexes but disable the
scheduler for writers.

> The readers can choose to spin, or do something else. ..

Boy, you're so stupid.

Re: Advanced (for me) Question About Keyword volatile

<svmt0c$594$3@dont-email.me>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=20672&group=comp.lang.c#20672

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: chris.m....@gmail.com (Chris M. Thomasson)
Newsgroups: comp.lang.c
Subject: Re: Advanced (for me) Question About Keyword volatile
Date: Tue, 1 Mar 2022 20:49:16 -0800
Organization: A noiseless patient Spider
Lines: 69
Message-ID: <svmt0c$594$3@dont-email.me>
References: <4eddd378-e045-4242-bf9e-bc0efae0cea5n@googlegroups.com>
<svh461$3jf$1@dont-email.me> <svkj9o$hqu$4@dont-email.me>
<svm3e0$3gj$1@dont-email.me> <svmp9f$hpc$1@dont-email.me>
<svmppj$l0t$1@dont-email.me> <svmqr5$qj0$1@dont-email.me>
<svmr4q$sh0$2@dont-email.me> <svmrp4$vlj$1@dont-email.me>
<svmshk$594$1@dont-email.me> <svmsn2$570$1@dont-email.me>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
Injection-Date: Wed, 2 Mar 2022 04:49:16 -0000 (UTC)
Injection-Info: reader02.eternal-september.org; posting-host="d4a417dfd5e5fa43753e81c21b04ad49";
logging-data="5412"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+3btEil08oFGVACk1fJvyCKuhRQSemn+Y="
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:91.0) Gecko/20100101
Thunderbird/91.6.1
Cancel-Lock: sha1:gczutHkfn8dF894BKTshbBovvrI=
In-Reply-To: <svmsn2$570$1@dont-email.me>
Content-Language: en-US
 by: Chris M. Thomasson - Wed, 2 Mar 2022 04:49 UTC

On 3/1/2022 8:44 PM, Bonita Montero wrote:
> Am 02.03.2022 um 05:41 schrieb Chris M. Thomasson:
>> On 3/1/2022 8:28 PM, Bonita Montero wrote:
>>> Am 02.03.2022 um 05:17 schrieb Chris M. Thomasson:
>>>> On 3/1/2022 8:12 PM, Bonita Montero wrote:
>>>>> Am 02.03.2022 um 04:54 schrieb Chris M. Thomasson:
>>>>>> On 3/1/2022 7:45 PM, Bonita Montero wrote:
>>>>>>> Am 01.03.2022 um 22:32 schrieb Chris M. Thomasson:
>>>>>>>> On 2/28/2022 11:51 PM, Bonita Montero wrote:
>>>>>>>>> Am 28.02.2022 um 01:14 schrieb Chris M. Thomasson:
>>>>>>>>>> On 2/27/2022 2:35 PM, das...@gmail.com wrote:
>>>>>>>>>>> I have 3 variables used as interface variables between 2
>>>>>>>>>>> threads. Thread A writes the variables, and Thread B reads
>>>>>>>>>>> them.  Let me call them v1, v2, and v3.
>>>>>>>>>>>
>>>>>>>>>>> I buffer (or snapshot) them into local variables.
>>>>>>>>>>>
>>>>>>>>>>> Question:  Do the local variables need to be declared
>>>>>>>>>>> volatile as well?
>>>>>>>>>>
>>>>>>>>>> The local variables are fine, and do not need to be
>>>>>>>>>> atomic/volatile, ect... Btw, think about using C atomic's
>>>>>>>>>> instead of volatile. You might be interested in a seqlock:
>>>>>>>>>> https://en.wikipedia.org/wiki/Seqlock
>>>>>>>>>> (read all)
>>>>>>>>>> They are geared to a read-mostly, write rarely pattern.
>>>>>>>>>
>>>>>>>>> Seqlocks don't make sense in user-space as they're lock-free and
>>>>>>>>> a writer, having made the seq-counter odd, may be easily scheduled
>>>>>>>>> away before making the seq-counter even again.
>>>>>>>>
>>>>>>>> Huh? The writers use a mutex. So, how lock-free is a writer?
>>>>>>>> For some reason, I don't think you have ever used one.
>>>>>>>
>>>>>>> Seqlocks need disabling the scheduler on a core while writing
>>>>>>> that a writer can't be scheduled away. That's not possible in
>>>>>>> user-mode.
>>>>>>
>>>>>> Huh? Wow. This basically confirms that you have never used a
>>>>>> seqlock in user land. Remember that the writer uses a normal
>>>>>> mutex. Now, a friend of mine created a really neat mutation of a
>>>>>> seqlock:
>>>>>
>>>>> No, readers and writers spin.
>>>>> Otherwise you don't have a seq-lock but sth. different.
>>>>> Look how it is implemented in the Linux kernel.
>>>>
>>>> Writers never spin. They use a lock. Read about the algorithm. Read
>>>> it again, and one more time.
>>>
>>> With seqlocks like in the kernel writer always spin.
>>> Seqlocks inside the kernel never use a mutex.
>>>
>>> And this seqlock-"implementation" on 1024 cores ist stupid.
>>
>> You really think so? Wow.
>
> Yes, with that implementaiton a writer could be scheduled away
> and a reader could spin for a long time.
> Seqlocks inside the kernel don't use mutexes but disable the
> scheduler for writers.
>
>> The readers can choose to spin, or do something else. ..
>
> Boy, you're so stupid.

Sigh. Yet another algorithm that you don't really know about. Just like
when you tried to say lock-free queues are useless. Many example of me
correcting you now.

Re: Advanced (for me) Question About Keyword volatile

<svmt1v$594$4@dont-email.me>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=20673&group=comp.lang.c#20673

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: chris.m....@gmail.com (Chris M. Thomasson)
Newsgroups: comp.lang.c
Subject: Re: Advanced (for me) Question About Keyword volatile
Date: Tue, 1 Mar 2022 20:50:07 -0800
Organization: A noiseless patient Spider
Lines: 100
Message-ID: <svmt1v$594$4@dont-email.me>
References: <4eddd378-e045-4242-bf9e-bc0efae0cea5n@googlegroups.com>
<svh461$3jf$1@dont-email.me> <svkj9o$hqu$4@dont-email.me>
<svm3e0$3gj$1@dont-email.me> <svmp9f$hpc$1@dont-email.me>
<svmppj$l0t$1@dont-email.me> <svmqr5$qj0$1@dont-email.me>
<svmrra$tr$1@dont-email.me> <svmsfh$49c$1@dont-email.me>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
Injection-Date: Wed, 2 Mar 2022 04:50:07 -0000 (UTC)
Injection-Info: reader02.eternal-september.org; posting-host="d4a417dfd5e5fa43753e81c21b04ad49";
logging-data="5412"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19JHJECoocsj2O7FDdHur3+oCSBdQZPHc8="
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:91.0) Gecko/20100101
Thunderbird/91.6.1
Cancel-Lock: sha1:vMApTK3C+f5mwXASOAMpcs3jRTI=
In-Reply-To: <svmsfh$49c$1@dont-email.me>
Content-Language: en-US
 by: Chris M. Thomasson - Wed, 2 Mar 2022 04:50 UTC

On 3/1/2022 8:40 PM, Bonita Montero wrote:
> Am 02.03.2022 um 05:29 schrieb Chris M. Thomasson:
>> On 3/1/2022 8:12 PM, Bonita Montero wrote:
>>> Am 02.03.2022 um 04:54 schrieb Chris M. Thomasson:
>>>> On 3/1/2022 7:45 PM, Bonita Montero wrote:
>>>>> Am 01.03.2022 um 22:32 schrieb Chris M. Thomasson:
>>>>>> On 2/28/2022 11:51 PM, Bonita Montero wrote:
>>>>>>> Am 28.02.2022 um 01:14 schrieb Chris M. Thomasson:
>>>>>>>> On 2/27/2022 2:35 PM, das...@gmail.com wrote:
>>>>>>>>> I have 3 variables used as interface variables between 2
>>>>>>>>> threads. Thread A writes the variables, and Thread B reads
>>>>>>>>> them.  Let me call them v1, v2, and v3.
>>>>>>>>>
>>>>>>>>> I buffer (or snapshot) them into local variables.
>>>>>>>>>
>>>>>>>>> Question:  Do the local variables need to be declared volatile
>>>>>>>>> as well?
>>>>>>>>
>>>>>>>> The local variables are fine, and do not need to be
>>>>>>>> atomic/volatile, ect... Btw, think about using C atomic's
>>>>>>>> instead of volatile. You might be interested in a seqlock:
>>>>>>>> https://en.wikipedia.org/wiki/Seqlock
>>>>>>>> (read all)
>>>>>>>> They are geared to a read-mostly, write rarely pattern.
>>>>>>>
>>>>>>> Seqlocks don't make sense in user-space as they're lock-free and
>>>>>>> a writer, having made the seq-counter odd, may be easily scheduled
>>>>>>> away before making the seq-counter even again.
>>>>>>
>>>>>> Huh? The writers use a mutex. So, how lock-free is a writer?
>>>>>> For some reason, I don't think you have ever used one.
>>>>>
>>>>> Seqlocks need disabling the scheduler on a core while writing
>>>>> that a writer can't be scheduled away. That's not possible in
>>>>> user-mode.
>>>>
>>>> Huh? Wow. This basically confirms that you have never used a seqlock
>>>> in user land. Remember that the writer uses a normal mutex. Now, a
>>>> friend of mine created a really neat mutation of a seqlock:
>>>
>>> No, readers and writers spin.
>>> Otherwise you don't have a seq-lock but sth. different.
>>> Look how it is implemented in the Linux kernel.
>>
>>
>> The basic seqlock minus the tricky membars:
>>
>> // quick and crude pseudo-code
>>
>> struct state { int a = 0; }
>> mutex g_lock;
>> atomic_unsigned g_ver = 0;
>>
>> state g_state;
>>
>> // writers
>> lock(g_lock);
>>    ++ver;
>>
>>      ++g_state.a;
>>
>>    ++ver;
>> unlock(g_lock);
>>
>>
>> // readers
>> state lstate;
>>
>> for (;;)
>> {
>>    unsigned ver0 = g_ver;
>>
>>      lstate = g_state;
>>
>>    unsigned ver1 = g_ver;
>>
>>
>>    if ((! (ver0 & 1)) && (ver0 == ver1))
>>    {
>>       break;
>>    }
>>
>>
>>    // A reader spun! Humm...
>>    // yield, backoff, do something else
>> }
>>
>>
>> The pattern is read-mostly, write-rarely. Fast reads, slow writes. It
>> works in user-land.
>
> Boy, you're so ultimately studpid.
>
> Readers could spin for a long time when whe writer is scheduled
> away. So the approach of 1024 cores is not tolerable in userspace
> and seqlocks only make sense in kernel space where the writer could
> disable scheduling while spinning of modifying.

A writer never spins! God damn it. LOL!

Re: Advanced (for me) Question About Keyword volatile

<svmtml$b27$1@dont-email.me>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=20675&group=comp.lang.c#20675

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: Bonita.M...@gmail.com (Bonita Montero)
Newsgroups: comp.lang.c
Subject: Re: Advanced (for me) Question About Keyword volatile
Date: Wed, 2 Mar 2022 06:01:13 +0100
Organization: A noiseless patient Spider
Lines: 74
Message-ID: <svmtml$b27$1@dont-email.me>
References: <4eddd378-e045-4242-bf9e-bc0efae0cea5n@googlegroups.com>
<svh461$3jf$1@dont-email.me> <svkj9o$hqu$4@dont-email.me>
<svm3e0$3gj$1@dont-email.me> <svmp9f$hpc$1@dont-email.me>
<svmppj$l0t$1@dont-email.me> <svmqr5$qj0$1@dont-email.me>
<svmr4q$sh0$2@dont-email.me> <svmrp4$vlj$1@dont-email.me>
<svmshk$594$1@dont-email.me> <svmsn2$570$1@dont-email.me>
<svmt0c$594$3@dont-email.me>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
Injection-Date: Wed, 2 Mar 2022 05:01:09 -0000 (UTC)
Injection-Info: reader02.eternal-september.org; posting-host="267f58128df590709f4eff4ce2840dfa";
logging-data="11335"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19IGk8NDMNl+0ujYJxeGKc4sTdj+O8MGg8="
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:91.0) Gecko/20100101
Thunderbird/91.6.1
Cancel-Lock: sha1:SWQonLjP56hRLgX4XZboop4f2Ec=
In-Reply-To: <svmt0c$594$3@dont-email.me>
Content-Language: de-DE
 by: Bonita Montero - Wed, 2 Mar 2022 05:01 UTC

Am 02.03.2022 um 05:49 schrieb Chris M. Thomasson:
> On 3/1/2022 8:44 PM, Bonita Montero wrote:
>> Am 02.03.2022 um 05:41 schrieb Chris M. Thomasson:
>>> On 3/1/2022 8:28 PM, Bonita Montero wrote:
>>>> Am 02.03.2022 um 05:17 schrieb Chris M. Thomasson:
>>>>> On 3/1/2022 8:12 PM, Bonita Montero wrote:
>>>>>> Am 02.03.2022 um 04:54 schrieb Chris M. Thomasson:
>>>>>>> On 3/1/2022 7:45 PM, Bonita Montero wrote:
>>>>>>>> Am 01.03.2022 um 22:32 schrieb Chris M. Thomasson:
>>>>>>>>> On 2/28/2022 11:51 PM, Bonita Montero wrote:
>>>>>>>>>> Am 28.02.2022 um 01:14 schrieb Chris M. Thomasson:
>>>>>>>>>>> On 2/27/2022 2:35 PM, das...@gmail.com wrote:
>>>>>>>>>>>> I have 3 variables used as interface variables between 2
>>>>>>>>>>>> threads. Thread A writes the variables, and Thread B reads
>>>>>>>>>>>> them.  Let me call them v1, v2, and v3.
>>>>>>>>>>>>
>>>>>>>>>>>> I buffer (or snapshot) them into local variables.
>>>>>>>>>>>>
>>>>>>>>>>>> Question:  Do the local variables need to be declared
>>>>>>>>>>>> volatile as well?
>>>>>>>>>>>
>>>>>>>>>>> The local variables are fine, and do not need to be
>>>>>>>>>>> atomic/volatile, ect... Btw, think about using C atomic's
>>>>>>>>>>> instead of volatile. You might be interested in a seqlock:
>>>>>>>>>>> https://en.wikipedia.org/wiki/Seqlock
>>>>>>>>>>> (read all)
>>>>>>>>>>> They are geared to a read-mostly, write rarely pattern.
>>>>>>>>>>
>>>>>>>>>> Seqlocks don't make sense in user-space as they're lock-free and
>>>>>>>>>> a writer, having made the seq-counter odd, may be easily
>>>>>>>>>> scheduled
>>>>>>>>>> away before making the seq-counter even again.
>>>>>>>>>
>>>>>>>>> Huh? The writers use a mutex. So, how lock-free is a writer?
>>>>>>>>> For some reason, I don't think you have ever used one.
>>>>>>>>
>>>>>>>> Seqlocks need disabling the scheduler on a core while writing
>>>>>>>> that a writer can't be scheduled away. That's not possible in
>>>>>>>> user-mode.
>>>>>>>
>>>>>>> Huh? Wow. This basically confirms that you have never used a
>>>>>>> seqlock in user land. Remember that the writer uses a normal
>>>>>>> mutex. Now, a friend of mine created a really neat mutation of a
>>>>>>> seqlock:
>>>>>>
>>>>>> No, readers and writers spin.
>>>>>> Otherwise you don't have a seq-lock but sth. different.
>>>>>> Look how it is implemented in the Linux kernel.
>>>>>
>>>>> Writers never spin. They use a lock. Read about the algorithm. Read
>>>>> it again, and one more time.
>>>>
>>>> With seqlocks like in the kernel writer always spin.
>>>> Seqlocks inside the kernel never use a mutex.
>>>>
>>>> And this seqlock-"implementation" on 1024 cores ist stupid.
>>>
>>> You really think so? Wow.
>>
>> Yes, with that implementaiton a writer could be scheduled away
>> and a reader could spin for a long time.
>> Seqlocks inside the kernel don't use mutexes but disable the
>> scheduler for writers.
>>
>>> The readers can choose to spin, or do something else. ..
>>
>> Boy, you're so stupid.
>
> Sigh. Yet another algorithm that you don't really know about. Just like
> when you tried to say lock-free queues are useless. Many example of me
> correcting you now.

No one practically uses lock-free queues because they need spinning.

Re: Advanced (for me) Question About Keyword volatile

<svmto3$bja$1@dont-email.me>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=20676&group=comp.lang.c#20676

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: chris.m....@gmail.com (Chris M. Thomasson)
Newsgroups: comp.lang.c
Subject: Re: Advanced (for me) Question About Keyword volatile
Date: Tue, 1 Mar 2022 21:01:53 -0800
Organization: A noiseless patient Spider
Lines: 57
Message-ID: <svmto3$bja$1@dont-email.me>
References: <4eddd378-e045-4242-bf9e-bc0efae0cea5n@googlegroups.com>
<svkl61$vca$1@dont-email.me>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
Injection-Date: Wed, 2 Mar 2022 05:01:56 -0000 (UTC)
Injection-Info: reader02.eternal-september.org; posting-host="d4a417dfd5e5fa43753e81c21b04ad49";
logging-data="11882"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/9uw41AMO6QkO7hvs2cRpy/C9GH7Zhet4="
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:91.0) Gecko/20100101
Thunderbird/91.6.1
Cancel-Lock: sha1:nGaxy6H9t263FHoD+4rb0NyWV+0=
In-Reply-To: <svkl61$vca$1@dont-email.me>
Content-Language: en-US
 by: Chris M. Thomasson - Wed, 2 Mar 2022 05:01 UTC

On 3/1/2022 12:23 AM, Bonita Montero wrote:
> Am 27.02.2022 um 23:35 schrieb das...@gmail.com:
>> I have 3 variables used as interface variables between 2 threads.
>> Thread A writes the variables, and Thread B reads them.  Let me call
>> them v1, v2, and v3.
>>
>> I buffer (or snapshot) them into local variables.
>>
>> Question:  Do the local variables need to be declared volatile as well?
>>
>> Thanks, Dave A.
>>
>> Code below.
>>
>> -----
>>
>> volatile int v1;
>> volatile int v2;
>> volatile int v3;
>>
>> void ThreadA(void)  //Writes the variables.
>> {
>>     //3 critical sections, but doesn't matter if ThreadB()
>>     //obtains values not obtained at exactly the same
>>     //time.
>>     ...
>>     MUTEX_BEGIN();
>>     v1 = expression1;
>>     MUTEX_END();
>>     ...
>>     MUTEX_BEGIN();
>>     v2 = expression2;
>>     MUTEX_END();
>>     ...
>>     MUTEX_BEGIN();
>>     v3 = expression3;
>>     MUTEX_END();
>> }
>
> If MUTEX_BEGIN() and MUTEX_END() include proper barriers
> no volatile is needed.
>

I think that is wrong Bonita. From what I can gather the following
scenario requires atomics and relaxed membars in the standard:

[0]: ThreadA: lock()
[1]: ThreadA: v1 = expression1;
[2]: ThreadA: unlock()
[3]: ThreadB: lock()
[4]: ThreadB: local_v2 = v2
[5]: ThreadB: unlock()

BAM! local_v2 just read v2 outside of the mutex protection. They need to
be atomic wrt the standard. relaxed membar can be used. I say this
because the OP did not fully explain what the expressions actually do. I
am assuming no data dependencies.

Re: Advanced (for me) Question About Keyword volatile

<svmtor$bja$2@dont-email.me>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=20677&group=comp.lang.c#20677

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: chris.m....@gmail.com (Chris M. Thomasson)
Newsgroups: comp.lang.c
Subject: Re: Advanced (for me) Question About Keyword volatile
Date: Tue, 1 Mar 2022 21:02:18 -0800
Organization: A noiseless patient Spider
Lines: 77
Message-ID: <svmtor$bja$2@dont-email.me>
References: <4eddd378-e045-4242-bf9e-bc0efae0cea5n@googlegroups.com>
<svh461$3jf$1@dont-email.me> <svkj9o$hqu$4@dont-email.me>
<svm3e0$3gj$1@dont-email.me> <svmp9f$hpc$1@dont-email.me>
<svmppj$l0t$1@dont-email.me> <svmqr5$qj0$1@dont-email.me>
<svmr4q$sh0$2@dont-email.me> <svmrp4$vlj$1@dont-email.me>
<svmshk$594$1@dont-email.me> <svmsn2$570$1@dont-email.me>
<svmt0c$594$3@dont-email.me> <svmtml$b27$1@dont-email.me>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
Injection-Date: Wed, 2 Mar 2022 05:02:19 -0000 (UTC)
Injection-Info: reader02.eternal-september.org; posting-host="d4a417dfd5e5fa43753e81c21b04ad49";
logging-data="11882"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18e8RpyujkcFw31sUWYNbkQaileT001jTU="
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:91.0) Gecko/20100101
Thunderbird/91.6.1
Cancel-Lock: sha1:cNLwTdZlQYEad8ls7K+zKSpdqmA=
In-Reply-To: <svmtml$b27$1@dont-email.me>
Content-Language: en-US
 by: Chris M. Thomasson - Wed, 2 Mar 2022 05:02 UTC

On 3/1/2022 9:01 PM, Bonita Montero wrote:
> Am 02.03.2022 um 05:49 schrieb Chris M. Thomasson:
>> On 3/1/2022 8:44 PM, Bonita Montero wrote:
>>> Am 02.03.2022 um 05:41 schrieb Chris M. Thomasson:
>>>> On 3/1/2022 8:28 PM, Bonita Montero wrote:
>>>>> Am 02.03.2022 um 05:17 schrieb Chris M. Thomasson:
>>>>>> On 3/1/2022 8:12 PM, Bonita Montero wrote:
>>>>>>> Am 02.03.2022 um 04:54 schrieb Chris M. Thomasson:
>>>>>>>> On 3/1/2022 7:45 PM, Bonita Montero wrote:
>>>>>>>>> Am 01.03.2022 um 22:32 schrieb Chris M. Thomasson:
>>>>>>>>>> On 2/28/2022 11:51 PM, Bonita Montero wrote:
>>>>>>>>>>> Am 28.02.2022 um 01:14 schrieb Chris M. Thomasson:
>>>>>>>>>>>> On 2/27/2022 2:35 PM, das...@gmail.com wrote:
>>>>>>>>>>>>> I have 3 variables used as interface variables between 2
>>>>>>>>>>>>> threads. Thread A writes the variables, and Thread B reads
>>>>>>>>>>>>> them.  Let me call them v1, v2, and v3.
>>>>>>>>>>>>>
>>>>>>>>>>>>> I buffer (or snapshot) them into local variables.
>>>>>>>>>>>>>
>>>>>>>>>>>>> Question:  Do the local variables need to be declared
>>>>>>>>>>>>> volatile as well?
>>>>>>>>>>>>
>>>>>>>>>>>> The local variables are fine, and do not need to be
>>>>>>>>>>>> atomic/volatile, ect... Btw, think about using C atomic's
>>>>>>>>>>>> instead of volatile. You might be interested in a seqlock:
>>>>>>>>>>>> https://en.wikipedia.org/wiki/Seqlock
>>>>>>>>>>>> (read all)
>>>>>>>>>>>> They are geared to a read-mostly, write rarely pattern.
>>>>>>>>>>>
>>>>>>>>>>> Seqlocks don't make sense in user-space as they're lock-free and
>>>>>>>>>>> a writer, having made the seq-counter odd, may be easily
>>>>>>>>>>> scheduled
>>>>>>>>>>> away before making the seq-counter even again.
>>>>>>>>>>
>>>>>>>>>> Huh? The writers use a mutex. So, how lock-free is a writer?
>>>>>>>>>> For some reason, I don't think you have ever used one.
>>>>>>>>>
>>>>>>>>> Seqlocks need disabling the scheduler on a core while writing
>>>>>>>>> that a writer can't be scheduled away. That's not possible in
>>>>>>>>> user-mode.
>>>>>>>>
>>>>>>>> Huh? Wow. This basically confirms that you have never used a
>>>>>>>> seqlock in user land. Remember that the writer uses a normal
>>>>>>>> mutex. Now, a friend of mine created a really neat mutation of a
>>>>>>>> seqlock:
>>>>>>>
>>>>>>> No, readers and writers spin.
>>>>>>> Otherwise you don't have a seq-lock but sth. different.
>>>>>>> Look how it is implemented in the Linux kernel.
>>>>>>
>>>>>> Writers never spin. They use a lock. Read about the algorithm.
>>>>>> Read it again, and one more time.
>>>>>
>>>>> With seqlocks like in the kernel writer always spin.
>>>>> Seqlocks inside the kernel never use a mutex.
>>>>>
>>>>> And this seqlock-"implementation" on 1024 cores ist stupid.
>>>>
>>>> You really think so? Wow.
>>>
>>> Yes, with that implementaiton a writer could be scheduled away
>>> and a reader could spin for a long time.
>>> Seqlocks inside the kernel don't use mutexes but disable the
>>> scheduler for writers.
>>>
>>>> The readers can choose to spin, or do something else. ..
>>>
>>> Boy, you're so stupid.
>>
>> Sigh. Yet another algorithm that you don't really know about. Just
>> like when you tried to say lock-free queues are useless. Many example
>> of me correcting you now.
>
> No one practically uses lock-free queues because they need spinning.
>

Sigh.

Pages:12
server_pubkey.txt

rocksolid light 0.9.8
clearnet tor