-
Notifications
You must be signed in to change notification settings - Fork 18.4k
Closed
Labels
Description
Unpack the attached archive and run gotest. I would expect the output to be around 1000, as both sleeps should sleep concurrently. Instead it prints around 2000 for me - the sleeps execute sequentially. If GOMAXPROCS > 0, it works as expected. 6g macos d9ff478c4ed3+ tip Here is the salient code from the archive: package tst //#include <unistd.h> // extern void BackgroundSleep(int); // void twoSleeps(int n){ // BackgroundSleep(n); // sleep(n); // } import "C" var sleepDone = make(chan bool) func ParSleep(n int){ C.twoSleeps(C.int(n)) <-sleepDone } //export BackgroundSleep func BackgroundSleep(n int){ // This function should start running immediately, // but it actually starts after twoSleeps has returned. go func(){ C.sleep(C.uint(n)) sleepDone <- true }() } func TestParSleep(t *testing.T) { t0 := time.Nanoseconds() ParSleep(1) fmt.Printf("%d\n", (time.Nanoseconds() - t0) / 1e6) }
Attachments:
- tstcgo.tgz (659 bytes)