3 ms·
Doesn't this just boil down to goroutines being lazy non-preemptive coroutines and not threads? setup() doesn't run before you block in the loop. In some implem
by nly 12y ago
Doesn't this just boil down to goroutines being lazy non-preemptive coroutines and not threads? setup() doesn't run before you block in the loop. In some implementations, coroutine run on construction, and you have to wait for it to yield for the first time before you can continue. In that scenario this code would exit. So it's less to do with the memory model, than it is the execution model.
Incidentally, it's platform dependent whether or not the C version will ever exit, although I'd guess that are many memory barriers inside pthread_exits guts and across kernel boundaries that effectively ensure it does. You'd definitely need a memory barrier somewhere to make returning a pointer from a joinable thread safe to use, for instance.