-
sneakerhead98[m]
are haveno and seraphis out yet? (or when are they expect if not featured yet?)
-
sneakerhead98[m]
s/expect/expected/
-
moneromooo
See #haveno-dev if you want to help that one. I *think* the main seraphis github repo is
github.com/UkoeHB/monero on a branch.
-
moneromooo
At least for seraphis, you still have a lot of time to help out.
-
jeffro256[m]
-
UkoeHB
C/C++ question: I have two shared_ptrs and want to guarantee sequential reads of their use counts (no compiler reordering). Is it sufficient to do this (or perhaps overkill?)? `volatile const size_t count1{ptr1.use_count()}; volatile const size_t count2{ptr2.use_count()};`
-
moneromooo
I don't think what you wrote would guarantee ordered reads anyway.
-
UkoeHB
what would be required to guarantee ordered reads then?
-
moneromooo
Looking :)
-
UkoeHB
it just has to be ordered reads from a single thread (reading these counts is locked by a mutex, and incrementing/decrementing them is correctly ordered by constructor/destructor rules)
-
UkoeHB
1. according to `volatile` (
en.cppreference.com/w/c/language/volatile ), "within a single thread of execution, a volatile access cannot be optimized out or reordered relative to another visible side effect that is separated by a sequence point from the volatile access." and then (
en.cppreference.com/w/c/language/eval_order ) "There is a sequence point after the evaluation of a full expression (an expression
-
UkoeHB
that is not a subexpression: typically something that ends with a semicolon..."
-
moneromooo
Hrm. The thing I was thinking of only works for std::atomic<T>. I don't suppose your refcounts are such ?
-
UkoeHB
don't think so
-
moneromooo
What you said would work (I think) if the refcounts wre atomic, not what you save them to.
-
moneromooo
The writes should be ordered, but not the reads AFAIK.
-
moneromooo
You want a memory barrier to be blunt, but that seems to be C++20...
-
moneromooo
That seems like an odd requirement btw.
-
moneromooo
Are you sure you need it ?
-
UkoeHB
yeah I have an idea for a safe pointer that has multithreaded value semantics... kind of hard to explain lol
-
moneromooo
Well, sorry then. I was thinking of atomic_load/atomic_store, doesn't apply.
-
UkoeHB
afaik all I need for it to work is that the use counts are guaranteed to be read in order, which seems to be what `volatile` achieves but I have never used that before
-
moneromooo
GCC seems to have sync_synchronize, which is a memory barrier (blunt).
-
moneromooo
volatile just means "the value may change behind the back of the program".
-
moneromooo
Basically for I/O.
-
moneromooo
So don't assume things.
-
UkoeHB
hmm ok, guess it's a harder problem than I expected
-
moneromooo
Well, if it's a test run, you can find a memory barrier for your OS/compiler. Like __sync_synchronize for GCC.
-
moneromooo
Blunt, but should do fine.
-
sech1
UkoeHB never use volatile for multi-thread synchronization, it's not designed for it
-
sech1
use std::atomic and std::memory_order
-
sech1
and std::atomic_thread_fence to guarantee memory ordering
-
moneromooo
That's for single thread IIUC.
-
moneromooo
Oh, nice, that looks like a C++11 memory barrier :D
-
UkoeHB
sech1: ok thanks, reading up on the thread fence now
-
sech1
std::atomic_thread_fence will work fine even within single thread, compiler will not reorder memory accesses around it
-
sech1
memory_order_acq_rel should be enough
-
UkoeHB
I'm thinking I might need fenced atomic ref counters too, if there is a risk that incrementing/decrementing the shared ptr internal ref counts won't have guaranteed ordering (even if constructor/destructor calls have guaranteed order)