For example I have a shared from different threads variable. What piece of code is correctly thread-safe?

First:
  shared class A
  {
      shared(int) x;

      void test1()
      {
          x = 10;
          x += 5
          writeln(x);
      }
  }

Or second:
  import core.atomic;
  shared class A
  {
      shared(int) x;

      void test1()
      {
          atomicStore(x, 10);
          atomicOp!("+=")(x, 5);
          writeln(atomicLoad(x));
      }
  }
  • thread-safe shared field acce... jj75607 via Digitalmars-d-learn

Reply via email to