#How to ensure compiler reordering instructions

8 messages · Page 1 of 1 (latest)

timber meadow
#

Dear guys I'm working on a C program with atomic reads and writes with multilple threads. However the compiler doesn't reorder instructions even with relaxed memory order. In what kinda cases does the compiler reorder instructions and how should I compile my instructions so that these optimisations take place

    atomic_store_explicit(&x, 1, memory_order_relaxed);
    atomic_store_explicit(&x, 2, memory_order_relaxed);
    // atomic_thread_fence(memory_order_seq_cst);
    printf("Thread A reads: %d\n", atomic_load_explicit(&y, memory_order_relaxed));
dark willowBOT
#

When your question is answered use !solved to mark the question as resolved.

Remember to ask specific questions, provide necessary details, and reduce your question to its simplest form. For tips on how to ask a good question use !howto ask.

azure copper
timber meadow
#

I have a x86 arch yes but im trying to create a program wich reports if there have been sc violations while executing

azure copper
#

wdym by "sc violations"?

timber meadow
#

sequential consistency violations

#

so basically po U mo U rf U fr cyclcity