Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <blockquote> <p>What's the fastest way to do this? (avoiding mutexes, locks, etc.)</p> </blockquote> <p>I'm pretty sure that you don't want to avoid mutexes. linux's futexes allow you to leverage the goodness of compare-and-swap (most of the time) while keeping the classic mutex semantic (the 'swap' that takes place is one of the mutex, not the code/data protected by it). I strongly suggest that you try them and profile the solution (<code>perf</code>, <code>oprofile</code>, VTune, etc) to see if your bottleneck is really related to the locking mechanism itself and not things like cache utilization, memory throughput, CPU cycles, IO access, remote-node memory accesses, etc.</p> <blockquote> <p>I think I'm running into some cache concurrency issues where sometimes it takes a bit of time before x finally gets updated with the new value.</p> </blockquote> <p>Well, let's assume you really do have a need to interact among processors and you've measured the latency hit that you get from futexes and you've determined that it won't meet your application's needs. So, if that's the case, a relatively sane way to proceed could be like so: create an array of 32-bit integers, padded out by a distance greater than or equal to the size of your target's cache line. Use the currently-executing CPU and cache line size as an index into the real values in this list (so if your cache line was 64 bytes, you would scale the CPU# by 16 to leap over the padding). You should write to these values only from the appropriate CPU and you can poll it from any other CPU (probably should call one of your CPU's "pause" instructions in the body of the busy-wait). This would be an effective mechanism for checking whether different execution threads have reached/satisfied a given condition.</p> <p>I should add that this will almost certainly work (effectively trading CPU efficiency for possibly lower latencies) but remain a very brittle solution for all but a very particular set of hardware.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload