Firstly, your OR condition will always hold true (either 0 on instantiation and not 1 when it is 0 or instantiated). So your while in foo1() is always true. But that issue isn't present with the other whiles.
Using mutex will be the best idea for such a situation. If u want to avoid it at any cost, put the codes in all 3 functions in while(true) loops and replace the currents whiles with ifs (making sure there's no nested whiles).