Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cgo: processes started from exported function are not scheduled correctly. #1560

Closed
rogpeppe opened this issue Feb 28, 2011 · 2 comments
Closed

Comments

@rogpeppe
Copy link
Contributor

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:

  1. tstcgo.tgz (659 bytes)
@rsc
Copy link
Contributor

rsc commented Feb 28, 2011

Comment 1:

Owner changed to r...@golang.org.

Status changed to Accepted.

@rsc
Copy link
Contributor

rsc commented Mar 7, 2011

Comment 2:

This issue was closed by revision f9ca3b5.

Status changed to Fixed.

@golang golang locked and limited conversation to collaborators Jun 24, 2016
@rsc rsc removed their assignment Jun 22, 2022
This issue was closed.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants