c# managing locking for access












1














I've been working for a while on locking resources (state objects) so that the only way to access them is by acquiring a lock, I wanted something with a lot of syntactic sugar so that once the lock is acquired the resource (object) is used via a reference without a need for special getters and setters.



Here is my code:



namespace Lockable {
public delegate void ActionRef<REF>(ref REF r1);
public delegate void ActionIn<REF>(in REF r1);
public delegate RES FuncRef<REF, RES>(ref REF r1);
public delegate RES FuncIn<REF, RES>(in REF r1);
public delegate void ActionRef<REF1, REF2>(ref REF1 r1, ref REF2 r2);
public delegate void ActionIn<REF1, REF2>(in REF1 r1, in REF2 r2);
public delegate RES FuncRef<REF1, REF2, RES>(ref REF1 r1, ref REF2 r2);
public delegate RES FuncIn<REF1, REF2, RES>(in REF1 r1, in REF2 r2);
public delegate void ActionRef<REF1, REF2, REF3>(ref REF1 r1, ref REF2 r2, ref REF3 r3);
public delegate void ActionIn<REF1, REF2, REF3>(in REF1 r1, in REF2 r2, in REF3 r3);
public delegate RES FuncRef<REF1, REF2, REF3, RES>(ref REF1 r1, ref REF2 r2, ref REF3 r3);
public delegate RES FuncIn<REF1, REF2, REF3, RES>(in REF1 r1, in REF2 r2, in REF3 r3);

public class Lockable<T> {
public Lockable() { }
public Lockable(T val) => this.val = val;
readonly object theLock = new object();
T val;

public void Lock(ActionRef<T> f) { lock (theLock) f(ref val); }
public void Lock(ActionIn<T> f) { lock (theLock) f(in val); }
public TRES Lock<TRES>(FuncRef<T, TRES> f) { lock (theLock) return f(ref val); }
public TRES Lock<TRES>(FuncIn<T, TRES> f) { lock (theLock) return f(in val); }

public class TwoLockable<T2> {
public TwoLockable(Lockable<T> val1, Lockable<T2> val2) { this.l1 = val1; this.l2 = val2; }
readonly Lockable<T> l1; readonly Lockable<T2> l2;

public void Lock(ActionRef<T, T2> f) { lock (l1.theLock) lock (l2.theLock) f(ref l1.val, ref l2.val); }
public void Lock(ActionIn<T, T2> f) { lock (l1.theLock) lock (l2.theLock) f(in l1.val, in l2.val); }
public TRES Lock<TRES>(FuncRef<T, T2, TRES> f) { lock (l1.theLock) lock (l2.theLock) return f(ref l1.val, ref l2.val); }
public TRES Lock<TRES>(FuncIn<T, T2, TRES> f) { lock (l1.theLock) lock (l2.theLock) return f(in l1.val, in l2.val); }

public class ThreeLockable<T3> {
public ThreeLockable(Lockable<T> val1, Lockable<T2> val2, Lockable<T3> val3) { this.l1 = val1; this.l2 = val2; this.l3 = val3; }
readonly Lockable<T> l1; readonly Lockable<T2> l2; readonly Lockable<T3> l3;

public void Lock(ActionRef<T, T2, T3> f) { lock (l1.theLock) lock (l2.theLock) lock (l3.theLock) f(ref l1.val, ref l2.val, ref l3.val); }
public void Lock(ActionIn<T, T2, T3> f) { lock (l1.theLock) lock (l2.theLock) lock (l3.theLock) f(in l1.val, in l2.val, in l3.val); }
public TRES Lock<TRES>(FuncRef<T, T2, T3, TRES> f) { lock (l1.theLock) lock (l2.theLock) lock (l3.theLock) return f(ref l1.val, ref l2.val, ref l3.val); }
public TRES Lock<TRES>(FuncIn<T, T2, T3, TRES> f) { lock (l1.theLock) lock (l2.theLock) lock (l3.theLock) return f(in l1.val, in l2.val, in l3.val); }
}
public ThreeLockable<T3> Combine<T3>(Lockable<T3> l3) => new ThreeLockable<T3>(this.l1, this.l2, l3);
}
public TwoLockable<T2> Combine<T2>(Lockable<T2> l2) => new TwoLockable<T2>(this, l2);
}
}


With the above code, I can now do this:



class State {
public readonly Lockable<Customers> Customers = new Lockable<Customers>(new Customers());
public readonly Lockable<Agents> Agents = new Lockable<Agents>(new Agents());
}


and then:



var S = new State(); // usually this will be a static/singleton


now the only way to access Customers is via the Lock method like this:



S.Customers.Lock((ref Customers Customers) => {
Log(Customers.GetPhone("John"));
Customers=new Customers();
Customers.Add("Mary");
});


or to return a value I can do:



var count = S.Customers.Lock((ref Customers Customers) => Customers.Count());


Note that you can use the above to modify the state without locking i.e.:



var UnlockedCustomers = S.Customers.Lock((ref Customers Customers) => Customers);
UnlockedCustomers.Add("Dave"); // unlocked !!!


This is by design as I wanted to allow that but make it very explicit in the code (unlike forgetting to lock..), if this is not desired the locks returning values need to be removed (FuncRefs etc)



If I need to lock both I combine the Locks:



S.Customers.Combine(S.Agents).Lock((ref Customers Customers, ref Agents Agents) => {
// both Agents and Customers are locked here !
});


I Included versions of combining 2 and 3 Lockables .. more can be added. Note that as with locks you have to always combine in the same order or risk deadlocks ... would be interesting to think of ways around this.



OK this is basically it. Note that this needs C# 7.3 .. also this is my first Code Review post so apologies if I broke any rules










share|improve this question









New contributor




kofifus is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.

























    1














    I've been working for a while on locking resources (state objects) so that the only way to access them is by acquiring a lock, I wanted something with a lot of syntactic sugar so that once the lock is acquired the resource (object) is used via a reference without a need for special getters and setters.



    Here is my code:



    namespace Lockable {
    public delegate void ActionRef<REF>(ref REF r1);
    public delegate void ActionIn<REF>(in REF r1);
    public delegate RES FuncRef<REF, RES>(ref REF r1);
    public delegate RES FuncIn<REF, RES>(in REF r1);
    public delegate void ActionRef<REF1, REF2>(ref REF1 r1, ref REF2 r2);
    public delegate void ActionIn<REF1, REF2>(in REF1 r1, in REF2 r2);
    public delegate RES FuncRef<REF1, REF2, RES>(ref REF1 r1, ref REF2 r2);
    public delegate RES FuncIn<REF1, REF2, RES>(in REF1 r1, in REF2 r2);
    public delegate void ActionRef<REF1, REF2, REF3>(ref REF1 r1, ref REF2 r2, ref REF3 r3);
    public delegate void ActionIn<REF1, REF2, REF3>(in REF1 r1, in REF2 r2, in REF3 r3);
    public delegate RES FuncRef<REF1, REF2, REF3, RES>(ref REF1 r1, ref REF2 r2, ref REF3 r3);
    public delegate RES FuncIn<REF1, REF2, REF3, RES>(in REF1 r1, in REF2 r2, in REF3 r3);

    public class Lockable<T> {
    public Lockable() { }
    public Lockable(T val) => this.val = val;
    readonly object theLock = new object();
    T val;

    public void Lock(ActionRef<T> f) { lock (theLock) f(ref val); }
    public void Lock(ActionIn<T> f) { lock (theLock) f(in val); }
    public TRES Lock<TRES>(FuncRef<T, TRES> f) { lock (theLock) return f(ref val); }
    public TRES Lock<TRES>(FuncIn<T, TRES> f) { lock (theLock) return f(in val); }

    public class TwoLockable<T2> {
    public TwoLockable(Lockable<T> val1, Lockable<T2> val2) { this.l1 = val1; this.l2 = val2; }
    readonly Lockable<T> l1; readonly Lockable<T2> l2;

    public void Lock(ActionRef<T, T2> f) { lock (l1.theLock) lock (l2.theLock) f(ref l1.val, ref l2.val); }
    public void Lock(ActionIn<T, T2> f) { lock (l1.theLock) lock (l2.theLock) f(in l1.val, in l2.val); }
    public TRES Lock<TRES>(FuncRef<T, T2, TRES> f) { lock (l1.theLock) lock (l2.theLock) return f(ref l1.val, ref l2.val); }
    public TRES Lock<TRES>(FuncIn<T, T2, TRES> f) { lock (l1.theLock) lock (l2.theLock) return f(in l1.val, in l2.val); }

    public class ThreeLockable<T3> {
    public ThreeLockable(Lockable<T> val1, Lockable<T2> val2, Lockable<T3> val3) { this.l1 = val1; this.l2 = val2; this.l3 = val3; }
    readonly Lockable<T> l1; readonly Lockable<T2> l2; readonly Lockable<T3> l3;

    public void Lock(ActionRef<T, T2, T3> f) { lock (l1.theLock) lock (l2.theLock) lock (l3.theLock) f(ref l1.val, ref l2.val, ref l3.val); }
    public void Lock(ActionIn<T, T2, T3> f) { lock (l1.theLock) lock (l2.theLock) lock (l3.theLock) f(in l1.val, in l2.val, in l3.val); }
    public TRES Lock<TRES>(FuncRef<T, T2, T3, TRES> f) { lock (l1.theLock) lock (l2.theLock) lock (l3.theLock) return f(ref l1.val, ref l2.val, ref l3.val); }
    public TRES Lock<TRES>(FuncIn<T, T2, T3, TRES> f) { lock (l1.theLock) lock (l2.theLock) lock (l3.theLock) return f(in l1.val, in l2.val, in l3.val); }
    }
    public ThreeLockable<T3> Combine<T3>(Lockable<T3> l3) => new ThreeLockable<T3>(this.l1, this.l2, l3);
    }
    public TwoLockable<T2> Combine<T2>(Lockable<T2> l2) => new TwoLockable<T2>(this, l2);
    }
    }


    With the above code, I can now do this:



    class State {
    public readonly Lockable<Customers> Customers = new Lockable<Customers>(new Customers());
    public readonly Lockable<Agents> Agents = new Lockable<Agents>(new Agents());
    }


    and then:



    var S = new State(); // usually this will be a static/singleton


    now the only way to access Customers is via the Lock method like this:



    S.Customers.Lock((ref Customers Customers) => {
    Log(Customers.GetPhone("John"));
    Customers=new Customers();
    Customers.Add("Mary");
    });


    or to return a value I can do:



    var count = S.Customers.Lock((ref Customers Customers) => Customers.Count());


    Note that you can use the above to modify the state without locking i.e.:



    var UnlockedCustomers = S.Customers.Lock((ref Customers Customers) => Customers);
    UnlockedCustomers.Add("Dave"); // unlocked !!!


    This is by design as I wanted to allow that but make it very explicit in the code (unlike forgetting to lock..), if this is not desired the locks returning values need to be removed (FuncRefs etc)



    If I need to lock both I combine the Locks:



    S.Customers.Combine(S.Agents).Lock((ref Customers Customers, ref Agents Agents) => {
    // both Agents and Customers are locked here !
    });


    I Included versions of combining 2 and 3 Lockables .. more can be added. Note that as with locks you have to always combine in the same order or risk deadlocks ... would be interesting to think of ways around this.



    OK this is basically it. Note that this needs C# 7.3 .. also this is my first Code Review post so apologies if I broke any rules










    share|improve this question









    New contributor




    kofifus is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
    Check out our Code of Conduct.























      1












      1








      1







      I've been working for a while on locking resources (state objects) so that the only way to access them is by acquiring a lock, I wanted something with a lot of syntactic sugar so that once the lock is acquired the resource (object) is used via a reference without a need for special getters and setters.



      Here is my code:



      namespace Lockable {
      public delegate void ActionRef<REF>(ref REF r1);
      public delegate void ActionIn<REF>(in REF r1);
      public delegate RES FuncRef<REF, RES>(ref REF r1);
      public delegate RES FuncIn<REF, RES>(in REF r1);
      public delegate void ActionRef<REF1, REF2>(ref REF1 r1, ref REF2 r2);
      public delegate void ActionIn<REF1, REF2>(in REF1 r1, in REF2 r2);
      public delegate RES FuncRef<REF1, REF2, RES>(ref REF1 r1, ref REF2 r2);
      public delegate RES FuncIn<REF1, REF2, RES>(in REF1 r1, in REF2 r2);
      public delegate void ActionRef<REF1, REF2, REF3>(ref REF1 r1, ref REF2 r2, ref REF3 r3);
      public delegate void ActionIn<REF1, REF2, REF3>(in REF1 r1, in REF2 r2, in REF3 r3);
      public delegate RES FuncRef<REF1, REF2, REF3, RES>(ref REF1 r1, ref REF2 r2, ref REF3 r3);
      public delegate RES FuncIn<REF1, REF2, REF3, RES>(in REF1 r1, in REF2 r2, in REF3 r3);

      public class Lockable<T> {
      public Lockable() { }
      public Lockable(T val) => this.val = val;
      readonly object theLock = new object();
      T val;

      public void Lock(ActionRef<T> f) { lock (theLock) f(ref val); }
      public void Lock(ActionIn<T> f) { lock (theLock) f(in val); }
      public TRES Lock<TRES>(FuncRef<T, TRES> f) { lock (theLock) return f(ref val); }
      public TRES Lock<TRES>(FuncIn<T, TRES> f) { lock (theLock) return f(in val); }

      public class TwoLockable<T2> {
      public TwoLockable(Lockable<T> val1, Lockable<T2> val2) { this.l1 = val1; this.l2 = val2; }
      readonly Lockable<T> l1; readonly Lockable<T2> l2;

      public void Lock(ActionRef<T, T2> f) { lock (l1.theLock) lock (l2.theLock) f(ref l1.val, ref l2.val); }
      public void Lock(ActionIn<T, T2> f) { lock (l1.theLock) lock (l2.theLock) f(in l1.val, in l2.val); }
      public TRES Lock<TRES>(FuncRef<T, T2, TRES> f) { lock (l1.theLock) lock (l2.theLock) return f(ref l1.val, ref l2.val); }
      public TRES Lock<TRES>(FuncIn<T, T2, TRES> f) { lock (l1.theLock) lock (l2.theLock) return f(in l1.val, in l2.val); }

      public class ThreeLockable<T3> {
      public ThreeLockable(Lockable<T> val1, Lockable<T2> val2, Lockable<T3> val3) { this.l1 = val1; this.l2 = val2; this.l3 = val3; }
      readonly Lockable<T> l1; readonly Lockable<T2> l2; readonly Lockable<T3> l3;

      public void Lock(ActionRef<T, T2, T3> f) { lock (l1.theLock) lock (l2.theLock) lock (l3.theLock) f(ref l1.val, ref l2.val, ref l3.val); }
      public void Lock(ActionIn<T, T2, T3> f) { lock (l1.theLock) lock (l2.theLock) lock (l3.theLock) f(in l1.val, in l2.val, in l3.val); }
      public TRES Lock<TRES>(FuncRef<T, T2, T3, TRES> f) { lock (l1.theLock) lock (l2.theLock) lock (l3.theLock) return f(ref l1.val, ref l2.val, ref l3.val); }
      public TRES Lock<TRES>(FuncIn<T, T2, T3, TRES> f) { lock (l1.theLock) lock (l2.theLock) lock (l3.theLock) return f(in l1.val, in l2.val, in l3.val); }
      }
      public ThreeLockable<T3> Combine<T3>(Lockable<T3> l3) => new ThreeLockable<T3>(this.l1, this.l2, l3);
      }
      public TwoLockable<T2> Combine<T2>(Lockable<T2> l2) => new TwoLockable<T2>(this, l2);
      }
      }


      With the above code, I can now do this:



      class State {
      public readonly Lockable<Customers> Customers = new Lockable<Customers>(new Customers());
      public readonly Lockable<Agents> Agents = new Lockable<Agents>(new Agents());
      }


      and then:



      var S = new State(); // usually this will be a static/singleton


      now the only way to access Customers is via the Lock method like this:



      S.Customers.Lock((ref Customers Customers) => {
      Log(Customers.GetPhone("John"));
      Customers=new Customers();
      Customers.Add("Mary");
      });


      or to return a value I can do:



      var count = S.Customers.Lock((ref Customers Customers) => Customers.Count());


      Note that you can use the above to modify the state without locking i.e.:



      var UnlockedCustomers = S.Customers.Lock((ref Customers Customers) => Customers);
      UnlockedCustomers.Add("Dave"); // unlocked !!!


      This is by design as I wanted to allow that but make it very explicit in the code (unlike forgetting to lock..), if this is not desired the locks returning values need to be removed (FuncRefs etc)



      If I need to lock both I combine the Locks:



      S.Customers.Combine(S.Agents).Lock((ref Customers Customers, ref Agents Agents) => {
      // both Agents and Customers are locked here !
      });


      I Included versions of combining 2 and 3 Lockables .. more can be added. Note that as with locks you have to always combine in the same order or risk deadlocks ... would be interesting to think of ways around this.



      OK this is basically it. Note that this needs C# 7.3 .. also this is my first Code Review post so apologies if I broke any rules










      share|improve this question









      New contributor




      kofifus is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.











      I've been working for a while on locking resources (state objects) so that the only way to access them is by acquiring a lock, I wanted something with a lot of syntactic sugar so that once the lock is acquired the resource (object) is used via a reference without a need for special getters and setters.



      Here is my code:



      namespace Lockable {
      public delegate void ActionRef<REF>(ref REF r1);
      public delegate void ActionIn<REF>(in REF r1);
      public delegate RES FuncRef<REF, RES>(ref REF r1);
      public delegate RES FuncIn<REF, RES>(in REF r1);
      public delegate void ActionRef<REF1, REF2>(ref REF1 r1, ref REF2 r2);
      public delegate void ActionIn<REF1, REF2>(in REF1 r1, in REF2 r2);
      public delegate RES FuncRef<REF1, REF2, RES>(ref REF1 r1, ref REF2 r2);
      public delegate RES FuncIn<REF1, REF2, RES>(in REF1 r1, in REF2 r2);
      public delegate void ActionRef<REF1, REF2, REF3>(ref REF1 r1, ref REF2 r2, ref REF3 r3);
      public delegate void ActionIn<REF1, REF2, REF3>(in REF1 r1, in REF2 r2, in REF3 r3);
      public delegate RES FuncRef<REF1, REF2, REF3, RES>(ref REF1 r1, ref REF2 r2, ref REF3 r3);
      public delegate RES FuncIn<REF1, REF2, REF3, RES>(in REF1 r1, in REF2 r2, in REF3 r3);

      public class Lockable<T> {
      public Lockable() { }
      public Lockable(T val) => this.val = val;
      readonly object theLock = new object();
      T val;

      public void Lock(ActionRef<T> f) { lock (theLock) f(ref val); }
      public void Lock(ActionIn<T> f) { lock (theLock) f(in val); }
      public TRES Lock<TRES>(FuncRef<T, TRES> f) { lock (theLock) return f(ref val); }
      public TRES Lock<TRES>(FuncIn<T, TRES> f) { lock (theLock) return f(in val); }

      public class TwoLockable<T2> {
      public TwoLockable(Lockable<T> val1, Lockable<T2> val2) { this.l1 = val1; this.l2 = val2; }
      readonly Lockable<T> l1; readonly Lockable<T2> l2;

      public void Lock(ActionRef<T, T2> f) { lock (l1.theLock) lock (l2.theLock) f(ref l1.val, ref l2.val); }
      public void Lock(ActionIn<T, T2> f) { lock (l1.theLock) lock (l2.theLock) f(in l1.val, in l2.val); }
      public TRES Lock<TRES>(FuncRef<T, T2, TRES> f) { lock (l1.theLock) lock (l2.theLock) return f(ref l1.val, ref l2.val); }
      public TRES Lock<TRES>(FuncIn<T, T2, TRES> f) { lock (l1.theLock) lock (l2.theLock) return f(in l1.val, in l2.val); }

      public class ThreeLockable<T3> {
      public ThreeLockable(Lockable<T> val1, Lockable<T2> val2, Lockable<T3> val3) { this.l1 = val1; this.l2 = val2; this.l3 = val3; }
      readonly Lockable<T> l1; readonly Lockable<T2> l2; readonly Lockable<T3> l3;

      public void Lock(ActionRef<T, T2, T3> f) { lock (l1.theLock) lock (l2.theLock) lock (l3.theLock) f(ref l1.val, ref l2.val, ref l3.val); }
      public void Lock(ActionIn<T, T2, T3> f) { lock (l1.theLock) lock (l2.theLock) lock (l3.theLock) f(in l1.val, in l2.val, in l3.val); }
      public TRES Lock<TRES>(FuncRef<T, T2, T3, TRES> f) { lock (l1.theLock) lock (l2.theLock) lock (l3.theLock) return f(ref l1.val, ref l2.val, ref l3.val); }
      public TRES Lock<TRES>(FuncIn<T, T2, T3, TRES> f) { lock (l1.theLock) lock (l2.theLock) lock (l3.theLock) return f(in l1.val, in l2.val, in l3.val); }
      }
      public ThreeLockable<T3> Combine<T3>(Lockable<T3> l3) => new ThreeLockable<T3>(this.l1, this.l2, l3);
      }
      public TwoLockable<T2> Combine<T2>(Lockable<T2> l2) => new TwoLockable<T2>(this, l2);
      }
      }


      With the above code, I can now do this:



      class State {
      public readonly Lockable<Customers> Customers = new Lockable<Customers>(new Customers());
      public readonly Lockable<Agents> Agents = new Lockable<Agents>(new Agents());
      }


      and then:



      var S = new State(); // usually this will be a static/singleton


      now the only way to access Customers is via the Lock method like this:



      S.Customers.Lock((ref Customers Customers) => {
      Log(Customers.GetPhone("John"));
      Customers=new Customers();
      Customers.Add("Mary");
      });


      or to return a value I can do:



      var count = S.Customers.Lock((ref Customers Customers) => Customers.Count());


      Note that you can use the above to modify the state without locking i.e.:



      var UnlockedCustomers = S.Customers.Lock((ref Customers Customers) => Customers);
      UnlockedCustomers.Add("Dave"); // unlocked !!!


      This is by design as I wanted to allow that but make it very explicit in the code (unlike forgetting to lock..), if this is not desired the locks returning values need to be removed (FuncRefs etc)



      If I need to lock both I combine the Locks:



      S.Customers.Combine(S.Agents).Lock((ref Customers Customers, ref Agents Agents) => {
      // both Agents and Customers are locked here !
      });


      I Included versions of combining 2 and 3 Lockables .. more can be added. Note that as with locks you have to always combine in the same order or risk deadlocks ... would be interesting to think of ways around this.



      OK this is basically it. Note that this needs C# 7.3 .. also this is my first Code Review post so apologies if I broke any rules







      c#






      share|improve this question









      New contributor




      kofifus is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.











      share|improve this question









      New contributor




      kofifus is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.









      share|improve this question




      share|improve this question








      edited 8 mins ago







      kofifus













      New contributor




      kofifus is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.









      asked 1 hour ago









      kofifuskofifus

      1062




      1062




      New contributor




      kofifus is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.





      New contributor





      kofifus is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.






      kofifus is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.






















          0






          active

          oldest

          votes











          Your Answer





          StackExchange.ifUsing("editor", function () {
          return StackExchange.using("mathjaxEditing", function () {
          StackExchange.MarkdownEditor.creationCallbacks.add(function (editor, postfix) {
          StackExchange.mathjaxEditing.prepareWmdForMathJax(editor, postfix, [["\$", "\$"]]);
          });
          });
          }, "mathjax-editing");

          StackExchange.ifUsing("editor", function () {
          StackExchange.using("externalEditor", function () {
          StackExchange.using("snippets", function () {
          StackExchange.snippets.init();
          });
          });
          }, "code-snippets");

          StackExchange.ready(function() {
          var channelOptions = {
          tags: "".split(" "),
          id: "196"
          };
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function() {
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled) {
          StackExchange.using("snippets", function() {
          createEditor();
          });
          }
          else {
          createEditor();
          }
          });

          function createEditor() {
          StackExchange.prepareEditor({
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: false,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: null,
          bindNavPrevention: true,
          postfix: "",
          imageUploader: {
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          },
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          });


          }
          });






          kofifus is a new contributor. Be nice, and check out our Code of Conduct.










          draft saved

          draft discarded


















          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fcodereview.stackexchange.com%2fquestions%2f211147%2fc-managing-locking-for-access%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown

























          0






          active

          oldest

          votes








          0






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes








          kofifus is a new contributor. Be nice, and check out our Code of Conduct.










          draft saved

          draft discarded


















          kofifus is a new contributor. Be nice, and check out our Code of Conduct.













          kofifus is a new contributor. Be nice, and check out our Code of Conduct.












          kofifus is a new contributor. Be nice, and check out our Code of Conduct.
















          Thanks for contributing an answer to Code Review Stack Exchange!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid



          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.


          Use MathJax to format equations. MathJax reference.


          To learn more, see our tips on writing great answers.





          Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


          Please pay close attention to the following guidance:


          • Please be sure to answer the question. Provide details and share your research!

          But avoid



          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.


          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fcodereview.stackexchange.com%2fquestions%2f211147%2fc-managing-locking-for-access%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          List directoties down one level, excluding some named directories and files

          list processes belonging to a network namespace

          list systemd RuntimeDirectory mounts