Using Manual Reset Event Set/Wait Methods
Intuition\nWe need to synchronize the method execution in multi threaded environment so same can be achived using ManualResetEventslim class.  \n\n# Approach\nW
# Intuition\nWe need to synchronize the method execution in multi threaded environment so same can be achived using ManualResetEventslim class.  \n\n# Approach\nWe can have two slim events, one to synchronize the call for first and second method to ensure that first always executed before second method. \nAnd second slim event is to make sure that second method gets executed before the third method. \nSo, we can intialize these instance in the constructions with disabled state. Till the time we enable them by calling Set method. The thread will wait on Wait method. \nAfter priting first, we can set the first slim event. If a thread is waiting at Wait method in second method will get notified about its status change and now will resume its work. Same will happen for second slim event. \n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```\nusing System.Threading;\n\npublic class Foo {\n\n     public ManualResetEventSlim slimEvent { get; set; }\n     public ManualResetEventSlim secondslimEvent { get; set; }\n\n    public Foo() \n    {\n        slimEvent = new ManualResetEventSlim(false);\n        secondslimEvent = new ManualResetEventSlim(false);\n    }\n\n    public void First(Action printFirst) \n    {\n        // printFirst() outputs "first". Do not change or remove this line.\n        printFirst();\n        slimEvent.Set();\n    }\n\n    public void Second(Action printSecond) \n    {\n        slimEvent.Wait();\n        \n        // printSecond() outputs "second". Do not change or remove this line.\n        printSecond();\n        secondslimEvent.Set();\n    }\n\n    public void Third(Action printThird) \n    {\n        secondslimEvent.Wait();\n        // printThird() outputs "third". Do not change or remove this line.\n        printThird();\n    }\n}\n```
['C#']