Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.os.linux.misc > #37442
| From | The Natural Philosopher <tnp@invalid.invalid> |
|---|---|
| Newsgroups | comp.os.linux.misc |
| Subject | Re: Contents of file changed while application is reading it |
| Date | 2023-03-06 09:20 +0000 |
| Organization | A little, after lunch |
| Message-ID | <tu4b99$vlig$23@dont-email.me> (permalink) |
| References | (17 earlier) <wwvcz5o7sfd.fsf@LkoBDZeT.terraraq.uk> <ttv5cm$27bbi$63@dont-email.me> <wwvmt4sn4lp.fsf@LkoBDZeT.terraraq.uk> <ttvbog$279gm$79@dont-email.me> <wwvjzzv4091.fsf@LkoBDZeT.terraraq.uk> |
On 05/03/2023 16:43, Richard Kettlewell wrote: > The Natural Philosopher <tnp@invalid.invalid> writes: >> On 04/03/2023 11:22, Richard Kettlewell wrote: >>> It’s suitable for coping with signals/interrupts too, yes. >>> The point that sometimes causes confusion is that it’s _not_ >>> suitable >>> for managing concurrent access from multiple threads. >> >> If I understand what exactly you mean by that, the question would be >> 'why not?' > > ‘volatile’ affects what assembler instructions the compiler generates - > it forces it to generate read and write instructions that otherwise > wouldn’t be there. > > However, at runtime, the CPU core may re-order memory operations > compared to how they appear in the assembler code, in pursuit of higher > performance. > > Within a single core, this is invisible the programmer: a re-ordering > isn’t allowed to change the execution of single-threaded code. > > With multiple cores, however, the effects can be visible. A memory write > on CPU 1 may not be visible in a memory read by CPU 2 for many cycles > after it was executed. There are more complex examples: for instance if > CPU 1 does two memory writes, CPU 2 might see the effect of the second > before the effect of the first. > > The exact rules differ between CPU architectures. x86 is one of the most > forgiving (though even there a store may be re-ordered after a load) - > presumably there is a lot of logic dedicated to maintaining consistency > between cores. Arm is one of the least forgiving. > > For a programmer there are two solutions (or three if you count avoiding > concurrency). > > * Use memory barrier instructions, which prohibit re-orderings across > them. These instructions are generally built into locks, semaphores, > etc, so properly written threaded code is already immunized against > the issue. > > This explains the language in > https://pubs.opengroup.org/onlinepubs/9699919799/basedefs/V1_chap04.html#tag_04_12: > it is telling us which functions have to include a memory barrier. > > * Use atomic operations, which provide a set of memory operations with > guarantees about re-ordering built in. > > (See https://en.cppreference.com/w/c/atomic for atomic operations in > C.) > Ah. Thanks Richard. I never thought about multiple *cores*. That explains it all nicely. -- It’s easier to fool people than to convince them that they have been fooled. Mark Twain
Back to comp.os.linux.misc | Previous | Next — Previous in thread | Next in thread | Find similar
Contents of file changed while application is reading it Clark Smith <noaddress@nowhere.net> - 2023-02-26 18:52 +0000
Re: Contents of file changed while application is reading it Rich <rich@example.invalid> - 2023-02-26 19:20 +0000
Re: Contents of file changed while application is reading it Robert Heller <heller@deepsoft.com> - 2023-02-26 21:45 +0000
Re: Contents of file changed while application is reading it "Carlos E.R." <robin_listas@es.invalid> - 2023-02-26 23:05 +0100
Re: Contents of file changed while application is reading it The Natural Philosopher <tnp@invalid.invalid> - 2023-02-26 23:38 +0000
Re: Contents of file changed while application is reading it The Natural Philosopher <tnp@invalid.invalid> - 2023-02-26 23:32 +0000
Re: Contents of file changed while application is reading it "David W. Hodgins" <dwhodgins@nomail.afraid.org> - 2023-02-26 19:06 -0500
Re: Contents of file changed while application is reading it The Natural Philosopher <tnp@invalid.invalid> - 2023-02-27 00:26 +0000
Re: Contents of file changed while application is reading it "David W. Hodgins" <dwhodgins@nomail.afraid.org> - 2023-02-26 20:48 -0500
Re: Contents of file changed while application is reading it Richard Kettlewell <invalid@invalid.invalid> - 2023-02-27 09:03 +0000
Re: Contents of file changed while application is reading it The Natural Philosopher <tnp@invalid.invalid> - 2023-02-27 09:58 +0000
Re: Contents of file changed while application is reading it "Carlos E.R." <robin_listas@es.invalid> - 2023-02-27 11:16 +0100
Re: Contents of file changed while application is reading it Richard Kettlewell <invalid@invalid.invalid> - 2023-02-27 15:20 +0000
Re: Contents of file changed while application is reading it "Carlos E.R." <robin_listas@es.invalid> - 2023-02-27 10:34 +0100
Re: Contents of file changed while application is reading it Richard Kettlewell <invalid@invalid.invalid> - 2023-02-27 09:49 +0000
Re: Contents of file changed while application is reading it "Carlos E.R." <robin_listas@es.invalid> - 2023-02-27 11:13 +0100
Re: Contents of file changed while application is reading it The Natural Philosopher <tnp@invalid.invalid> - 2023-02-27 10:02 +0000
Re: Contents of file changed while application is reading it "Carlos E.R." <robin_listas@es.invalid> - 2023-02-27 11:13 +0100
Re: Contents of file changed while application is reading it The Natural Philosopher <tnp@invalid.invalid> - 2023-02-27 10:17 +0000
Re: Contents of file changed while application is reading it "David W. Hodgins" <dwhodgins@nomail.afraid.org> - 2023-02-27 12:27 -0500
Re: Contents of file changed while application is reading it "Carlos E.R." <robin_listas@es.invalid> - 2023-02-27 19:19 +0100
Re: Contents of file changed while application is reading it "28A.I873" <28A.I873@noabzba.net> - 2023-02-27 21:46 -0500
Re: Contents of file changed while application is reading it "Carlos E.R." <robin_listas@es.invalid> - 2023-02-28 13:33 +0100
Re: Contents of file changed while application is reading it "28A.I873" <28A.I873@noabzba.net> - 2023-02-28 10:49 -0500
Re: Contents of file changed while application is reading it The Natural Philosopher <tnp@invalid.invalid> - 2023-02-28 16:21 +0000
Re: Contents of file changed while application is reading it "28A.I873" <28A.I873@noabzba.net> - 2023-03-01 01:05 -0500
Re: Contents of file changed while application is reading it Charlie Gibbs <cgibbs@kltpzyxm.invalid> - 2023-03-01 21:57 +0000
Re: Contents of file changed while application is reading it "28A.I873" <28A.I873@noabzba.net> - 2023-03-01 22:53 -0500
Re: Contents of file changed while application is reading it Charlie Gibbs <cgibbs@kltpzyxm.invalid> - 2023-03-02 19:06 +0000
Re: Contents of file changed while application is reading it "28A.I873" <28A.I873@noabzba.net> - 2023-03-02 23:08 -0500
Re: Contents of file changed while application is reading it Charlie Gibbs <cgibbs@kltpzyxm.invalid> - 2023-03-03 05:23 +0000
Re: Contents of file changed while application is reading it The Natural Philosopher <tnp@invalid.invalid> - 2023-03-03 09:36 +0000
Re: Contents of file changed while application is reading it "Carlos E.R." <robin_listas@es.invalid> - 2023-03-03 11:19 +0100
Re: Contents of file changed while application is reading it Charlie Gibbs <cgibbs@kltpzyxm.invalid> - 2023-03-03 15:58 +0000
Re: Contents of file changed while application is reading it "Carlos E. R." <robin_listas@es.invalid> - 2023-03-03 18:47 +0100
Re: Contents of file changed while application is reading it Rich <rich@example.invalid> - 2023-03-04 16:24 +0000
Re: Contents of file changed while application is reading it "Carlos E.R." <robin_listas@es.invalid> - 2023-03-04 18:40 +0100
Re: Contents of file changed while application is reading it The Natural Philosopher <tnp@invalid.invalid> - 2023-03-03 18:44 +0000
Re: Contents of file changed while application is reading it Charlie Gibbs <cgibbs@kltpzyxm.invalid> - 2023-03-04 01:25 +0000
Re: Contents of file changed while application is reading it Rich <rich@example.invalid> - 2023-03-04 16:21 +0000
Re: Contents of file changed while application is reading it "28B.I874" <28B.I874@noabzba.net> - 2023-03-04 23:55 -0500
Re: Contents of file changed while application is reading it Charlie Gibbs <cgibbs@kltpzyxm.invalid> - 2023-03-05 05:35 +0000
Re: Contents of file changed while application is reading it Allodoxaphobia <trepidation@example.net> - 2023-03-05 13:48 +0000
Re: Contents of file changed while application is reading it The Natural Philosopher <tnp@invalid.invalid> - 2023-03-05 14:01 +0000
Re: Contents of file changed while application is reading it Charlie Gibbs <cgibbs@kltpzyxm.invalid> - 2023-03-05 19:16 +0000
Re: Contents of file changed while application is reading it "28B.I874" <28B.I874@noabzba.net> - 2023-03-06 00:43 -0500
Re: Contents of file changed while application is reading it "28B.I874" <28B.I874@noabzba.net> - 2023-03-06 00:42 -0500
Re: Contents of file changed while application is reading it "David W. Hodgins" <dwhodgins@nomail.afraid.org> - 2023-02-28 12:01 -0500
Re: Contents of file changed while application is reading it "28A.I873" <28A.I873@noabzba.net> - 2023-03-01 01:17 -0500
Re: Contents of file changed while application is reading it Robert Riches <spamtrap42@jacob21819.net> - 2023-02-28 04:13 +0000
Re: Contents of file changed while application is reading it "Carlos E.R." <robin_listas@es.invalid> - 2023-02-28 13:16 +0100
Re: Contents of file changed while application is reading it "28A.I873" <28A.I873@noabzba.net> - 2023-03-01 01:32 -0500
Re: Contents of file changed while application is reading it The Natural Philosopher <tnp@invalid.invalid> - 2023-03-01 10:30 +0000
Re: Contents of file changed while application is reading it "28A.I873" <28A.I873@noabzba.net> - 2023-03-01 22:48 -0500
Re: Contents of file changed while application is reading it The Natural Philosopher <tnp@invalid.invalid> - 2023-03-02 09:41 +0000
Re: Contents of file changed while application is reading it "28A.I873" <28A.I873@noabzba.net> - 2023-03-02 23:39 -0500
Re: Contents of file changed while application is reading it The Natural Philosopher <tnp@invalid.invalid> - 2023-03-03 09:28 +0000
Re: Contents of file changed while application is reading it "David W. Hodgins" <dwhodgins@nomail.afraid.org> - 2023-03-03 12:16 -0500
Re: Contents of file changed while application is reading it "28A.I873" <28A.I873@noabzba.net> - 2023-03-04 01:36 -0500
Re: Contents of file changed while application is reading it The Natural Philosopher <tnp@invalid.invalid> - 2023-03-04 07:15 +0000
Re: Contents of file changed while application is reading it "28A.I873" <28A.I873@noabzba.net> - 2023-03-04 02:47 -0500
Re: Contents of file changed while application is reading it "28A.I873" <28A.I873@noabzba.net> - 2023-03-04 01:12 -0500
Re: Contents of file changed while application is reading it The Natural Philosopher <tnp@invalid.invalid> - 2023-03-04 06:51 +0000
Re: Contents of file changed while application is reading it "28A.I873" <28A.I873@noabzba.net> - 2023-03-04 03:32 -0500
Re: Contents of file changed while application is reading it Richard Kettlewell <invalid@invalid.invalid> - 2023-03-04 09:54 +0000
Re: Contents of file changed while application is reading it The Natural Philosopher <tnp@invalid.invalid> - 2023-03-04 10:09 +0000
Re: Contents of file changed while application is reading it Richard Kettlewell <invalid@invalid.invalid> - 2023-03-04 11:22 +0000
Re: Contents of file changed while application is reading it The Natural Philosopher <tnp@invalid.invalid> - 2023-03-04 11:58 +0000
Re: Contents of file changed while application is reading it Richard Kettlewell <invalid@invalid.invalid> - 2023-03-05 16:43 +0000
Re: Contents of file changed while application is reading it The Natural Philosopher <tnp@invalid.invalid> - 2023-03-06 09:20 +0000
Re: Contents of file changed while application is reading it "28B.I874" <28B.I874@noabzba.net> - 2023-03-04 20:24 -0500
Re: Contents of file changed while application is reading it The Natural Philosopher <tnp@invalid.invalid> - 2023-03-05 13:40 +0000
Re: Contents of file changed while application is reading it Dan Espen <dan1espen@gmail.com> - 2023-03-05 11:29 -0500
Re: Contents of file changed while application is reading it "28B.I874" <28B.I874@noabzba.net> - 2023-03-06 01:21 -0500
Re: Contents of file changed while application is reading it "28B.I874" <28B.I874@noabzba.net> - 2023-03-06 01:06 -0500
Re: Contents of file changed while application is reading it The Natural Philosopher <tnp@invalid.invalid> - 2023-03-06 09:28 +0000
Re: Contents of file changed while application is reading it "28B.I874" <28B.I874@noabzba.net> - 2023-03-06 08:54 -0500
Re: Contents of file changed while application is reading it Dan Espen <dan1espen@gmail.com> - 2023-02-26 17:35 -0500
Re: Contents of file changed while application is reading it The Natural Philosopher <tnp@invalid.invalid> - 2023-02-26 23:39 +0000
Re: Contents of file changed while application is reading it "28A.I873" <28A.I873@noabzba.net> - 2023-02-26 22:42 -0500
Re: Contents of file changed while application is reading it "Carlos E.R." <robin_listas@es.invalid> - 2023-02-27 10:45 +0100
Re: Contents of file changed while application is reading it The Natural Philosopher <tnp@invalid.invalid> - 2023-02-26 23:31 +0000
csiph-web