Data-race freedom is not guaranteed even with single-threaded code, because code can yield to other tasks on the same thread. @async can help prevent execution on other threads (so f and g will execute on the same thread in your example), but proper usage of locking and other synchronization primitives may be required to ensure that you don’t have races between f and g.
1 Like