Can anyone help me understand why am I getting TLE?
This seems to be failing for n=4. When running the code in Intellij it seems to work fine:\n\n\nclass FooBar {\n    private final int n;\n    private volatile i
This seems to be failing for n=4. When running the code in Intellij it seems to work fine:\n\n```\nclass FooBar {\n    private final int n;\n    private volatile int k = 0;\n\n    public FooBar(int n) {\n        this.n = n;\n    }\n\n    public void foo(Runnable printFoo) throws InterruptedException {        \n        for (int i = 0; i < n; i++) {\n            while (k % 2 == 1);\n        \tprintFoo.run();\n            k++;\n        }\n    }\n\n    public void bar(Runnable printBar) throws InterruptedException {        \n        for (int i = 0; i < n; i++) {\n            while (k % 2 == 0);\n        \tprintBar.run();\n            k++;\n        }\n    }\n}\n```\n\nThis relies on spinlocks (which in this case I would expect would be OK).
[]