- Why volatile may make sense for parallel code today. - 19 Updates
- A Java- / .NET-like monitor - 6 Updates
| Bonita Montero <Bonita.Montero@gmail.com>: Nov 24 05:26AM +0100 Am 23.11.2023 um 20:56 schrieb Scott Lurndal: >>> std::atomic<size_t> r >> The trick with my code > That's enough to fail a job interview.... ... with a nerd like you. |
| Bonita Montero <Bonita.Montero@gmail.com>: Nov 24 05:27AM +0100 Am 23.11.2023 um 21:32 schrieb Kaz Kylheku: > BTW, is the C++ lambda too broken to access the r via lexical scoping? > Why can't the APC just do "--r". > I believe local functions in Pascal from 1971 can do this. I already corrected that with my code and I guessed no one will notice that here; usually I'm right with that. |
| "Chris M. Thomasson" <chris.m.thomasson.1@gmail.com>: Nov 23 09:47PM -0800 On 11/23/2023 11:56 AM, Scott Lurndal wrote: >>> std::atomic<size_t> r >> The trick with my code > That's enough to fail a job interview.... Wow, no shit Scott. Yikes! |
| "Chris M. Thomasson" <chris.m.thomasson.1@gmail.com>: Nov 23 09:53PM -0800 On 11/23/2023 8:26 PM, Bonita Montero wrote: >>> The trick with my code >> That's enough to fail a job interview.... > ... with a nerd like you. Huh? What does that even mean? Really, humm... ;^o |
| "Chris M. Thomasson" <chris.m.thomasson.1@gmail.com>: Nov 23 09:55PM -0800 On 11/23/2023 8:27 PM, Bonita Montero wrote: >> I believe local functions in Pascal from 1971 can do this. > I already corrected that with my code and I guessed no one will notice > that here; usually I'm right with that. Usually, wrong, or always right? humm... |
| "Chris M. Thomasson" <chris.m.thomasson.1@gmail.com>: Nov 23 09:59PM -0800 On 11/23/2023 8:26 PM, Bonita Montero wrote: >>> The trick with my code >> That's enough to fail a job interview.... > ... with a nerd like you. Do you secretly like nerds? https://youtu.be/7dP1Vp1E-bo lol! |
| "Chris M. Thomasson" <chris.m.thomasson.1@gmail.com>: Nov 23 10:05PM -0800 On 11/23/2023 8:20 AM, Bonita Montero wrote: >> that it wlll get the most recent value that has happened "before" the >> read (as determined by memory order). > ... and the read is atomic - even if the trivial object is 1kB in size. humm.. Say, the read is from a word in memory. Define your trivial object, POD, l2 cache line sized, and aligned on a l2 cache line boundary? Are you refering to how certain arch works? |
| "Chris M. Thomasson" <chris.m.thomasson.1@gmail.com>: Nov 23 10:53PM -0800 On 11/23/2023 10:05 PM, Chris M. Thomasson wrote: > humm.. Say, the read is from a word in memory. Define your trivial > object, POD, l2 cache line sized, and aligned on a l2 cache line > boundary? Are you refering to how certain arch works? How many words in your cache lines, say l2? |
| Bonita Montero <Bonita.Montero@gmail.com>: Nov 24 08:53AM +0100 Am 24.11.2023 um 07:05 schrieb Chris M. Thomasson: > humm.. Say, the read is from a word in memory. Define your trivial > object, POD, l2 cache line sized, and aligned on a l2 cache line > boundary? Are you refering to how certain arch works? Read that: https://stackoverflow.com/questions/61329240/what-is-the-difference-between-trivial-and-non-trivial-objects |
| Bonita Montero <Bonita.Montero@gmail.com>: Nov 24 08:57AM +0100 Am 23.11.2023 um 18:50 schrieb Richard Damon: > there is no requirement to refetch the data if the code still has the > old value around, and it hasn't been invalidated by possible memory > ordering. I don't believe that, think about an atomic flag that is periodically polled. The compiler shouldn't cache that value. |
| "Chris M. Thomasson" <chris.m.thomasson.1@gmail.com>: Nov 24 12:16AM -0800 On 11/23/2023 11:57 PM, Bonita Montero wrote: >> ordering. > I don't believe that, think about an atomic flag that is periodically > polled. The compiler shouldn't cache that value. std::atomic is going to work for such a flag. Depending on your setup, it should be using std::memory_order_relaxed for the polling. |
| Bonita Montero <Bonita.Montero@gmail.com>: Nov 24 09:30AM +0100 Am 24.11.2023 um 09:16 schrieb Chris M. Thomasson: > std::atomic is going to work for such a flag. Depending on your > setup, it should be using std::memory_order_relaxed for the polling. There's also atomic_flag, but it has some limitations over atomic_bool that I've never used it. You can set it only in conjunction with an atomic read and I never had a use for that. And this relies on a atomic exchange, which costs a lot more than just a byte write. |
| "Chris M. Thomasson" <chris.m.thomasson.1@gmail.com>: Nov 24 01:04AM -0800 On 11/24/2023 12:30 AM, Bonita Montero wrote: > that I've never used it. You can set it only in conjunction with an > atomic read and I never had a use for that. And this relies on a atomic > exchange, which costs a lot more than just a byte write. Fwiw, this flag should be aligned on a l2 cache line boundary, and padded up to a l2 cache line size. |
| "Chris M. Thomasson" <chris.m.thomasson.1@gmail.com>: Nov 24 01:05AM -0800 On 11/24/2023 1:04 AM, Chris M. Thomasson wrote: >> exchange, which costs a lot more than just a byte write. > Fwiw, this flag should be aligned on a l2 cache line boundary, and > padded up to a l2 cache line size. You can stuff a cache line with words, as long as you do not straddle a cache line boundary... YIKES! |
| "Chris M. Thomasson" <chris.m.thomasson.1@gmail.com>: Nov 24 01:06AM -0800 On 11/23/2023 11:53 PM, Bonita Montero wrote: >> boundary? Are you refering to how certain arch works? > Read that: > https://stackoverflow.com/questions/61329240/what-is-the-difference-between-trivial-and-non-trivial-objects I know. Btw, what the hell happened to std::is_pod? ;^) |
| David Brown <david.brown@hesbynett.no>: Nov 24 10:08AM +0100 On 23/11/2023 20:55, Scott Lurndal wrote: > is, and won't be affected of someone accidentially removes the > volatile qualifier from the declaration of r. > Works just fine in c++, too. That is often my preference too, since it is the access that is "volatile" - a "volatile object" is simply one for which all accesses are "volatile". For the pedants, it might be worth noting that the "cast to pointer to volatile" technique of ACCESS_ONCE is not actually guaranteed to be treated as a volatile access in C until C17/C18 when the wording was changed to talk about accesses via "volatile lvalues" rather than accesses to objects declared as volatile. (When the topic was discussed by the committee, everyone agreed that all known compiler vendors treated "cast to pointer to volatile" accesses as volatile, so the change was a formality rather than any practical difference.) I don't know if and when this change was added to C++. |
| Bonita Montero <Bonita.Montero@gmail.com>: Nov 24 10:10AM +0100 Am 24.11.2023 um 10:06 schrieb Chris M. Thomasson: >> Read that: >> https://stackoverflow.com/questions/61329240/what-is-the-difference-between-trivial-and-non-trivial-objects > I know. Btw, what the hell happened to std::is_pod? ;^) PODs are also trivial but go beyond since you can copy them with a memcpy(): |
| "Chris M. Thomasson" <chris.m.thomasson.1@gmail.com>: Nov 24 01:14AM -0800 On 11/23/2023 8:20 AM, Bonita Montero wrote: >> that it wlll get the most recent value that has happened "before" the >> read (as determined by memory order). > ... and the read is atomic - even if the trivial object is 1kB in size. How is that read atomic with 1kb of data? On what arch? |
| David Brown <david.brown@hesbynett.no>: Nov 24 10:23AM +0100 On 23/11/2023 18:50, Richard Damon wrote: > need to consider possible action by other "threads" but only as far a > constrained by memory order, so two reads in the same ordering "slot" > are not forced. That is exactly how I see it (I also do not consider myself an expert in this area). I cannot see any requirement in the description of the execution, covering sequencing, ordering, "happens before", and all the rest, that suggests that the number of atomic accesses, or their order amongst each other, or their order with respect to volatile accesses or non-volatile accesses, is forced to follow the source code except where the atomics have specific sequencing. Atomic accesses are not "volatile" - they are not, in themselves, "observable behaviour". Because the the sequencing requirements for atomics depends partly on things happening in other threads, compilers are much more limited in how they can re-order or otherwise optimise atomic accesses than they are for normal accesses (unless the compiler knows all about the other threads too!). Compilers must be pessimistic about optimisation. But for certain simple cases, such as multiple neighbouring atomic reads of the same address or multiple neighbouring writes to the same address, I can't see any reason why they cannot be combined. (Again, I am not an expert here - and I will be happy to be corrected. They say the best way to learn something on the internet is not by asking questions, but by writing something that is wrong!) |
| "Chris M. Thomasson" <chris.m.thomasson.1@gmail.com>: Nov 23 09:35PM -0800 On 11/23/2023 3:14 PM, Michael S wrote: >> Today, Microsoft provides condition variables. > Which, I would guess, never used by 99.9% of programs that were not > ported to Windows from some other platform. Fwiw, check this out: https://sourceware.org/pthreads-win32/ ;^) |
| "Chris M. Thomasson" <chris.m.thomasson.1@gmail.com>: Nov 23 09:38PM -0800 On 11/21/2023 1:25 AM, Bonita Montero wrote: > Am 20.11.2023 um 21:18 schrieb Chris M. Thomasson: >> Did you read that article on MSDN as well? Iirc, its around 20 years old. > Has WFMO ever changed ? No, I don't think so.. The interesting aspect was about trying to avoid starvation the the wait array wrt the IOCP vs Event contest. So, we were advised to randomize and/or shift the positions wrt the event side wrt WFMO. |
| Bonita Montero <Bonita.Montero@gmail.com>: Nov 24 08:56AM +0100 Am 24.11.2023 um 06:38 schrieb Chris M. Thomasson: > starvation the the wait array wrt the IOCP vs Event contest. So, we were > advised to randomize and/or shift the positions wrt the event side wrt > WFMO. You officially can't wait for an IOCP handle with WFMO, although this actually works with my Windows 11 computer. MS should document that and make a statement since which Windows version this actually works. This isn't a strong requirement but it would be nice to wait for IOCPs with WFMO in some cases. |
| Bonita Montero <Bonita.Montero@gmail.com>: Nov 24 08:59AM +0100 Am 24.11.2023 um 06:35 schrieb Chris M. Thomasson: >> ported to Windows from some other platform. > Fwiw, check this out: > https://sourceware.org/pthreads-win32/ Am 24.11.2023 um 06:35 schrieb Chris M. Thomasson: That's an unnecessary discussion for a C++ programmer since the RAII-ish mutexes and condition variables since C++11 are more convenient to use. |
| "Chris M. Thomasson" <chris.m.thomasson.1@gmail.com>: Nov 24 01:17AM -0800 On 11/23/2023 11:59 PM, Bonita Montero wrote: > That's an unnecessary discussion for a C++ programmer since the RAII-ish > mutexes and condition variables since C++11 are more convenient to use. Have you ever wrapped up a C API in C++ using RAII before? |
| "Chris M. Thomasson" <chris.m.thomasson.1@gmail.com>: Nov 24 01:22AM -0800 On 11/23/2023 11:56 PM, Bonita Montero wrote: > make a statement since which Windows version this actually works. This > isn't a strong requirement but it would be nice to wait for IOCPs with > WFMO in some cases. Humm... You should be using: https://learn.microsoft.com/en-us/windows/win32/fileio/getqueuedcompletionstatusex-func |
| You received this digest because you're subscribed to updates for this group. You can change your settings on the group membership page. To unsubscribe from this group and stop receiving emails from it send an email to comp.lang.c+++unsubscribe@googlegroups.com. |