{"action":"created","issue":{"url":"https://api.github.com/repos/coreos/etcd/issues/2944","labels_url":"https://api.github.com/repos/coreos/etcd/issues/2944/labels{/name}","comments_url":"https://api.github.com/repos/coreos/etcd/issues/2944/comments","events_url":"https://api.github.com/repos/coreos/etcd/issues/2944/events","html_url":"https://github.com/coreos/etcd/pull/2944","id":86837156,"number":2944,"title":"pkg/testutil: ForceGosched -> WaitAllGoroutinesBlocked","user":{"login":"yichengq","id":2976232,"avatar_url":"https://avatars.githubusercontent.com/u/2976232?v=3","gravatar_id":"","url":"https://api.github.com/users/yichengq","html_url":"https://github.com/yichengq","followers_url":"https://api.github.com/users/yichengq/followers","following_url":"https://api.github.com/users/yichengq/following{/other_user}","gists_url":"https://api.github.com/users/yichengq/gists{/gist_id}","starred_url":"https://api.github.com/users/yichengq/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/yichengq/subscriptions","organizations_url":"https://api.github.com/users/yichengq/orgs","repos_url":"https://api.github.com/users/yichengq/repos","events_url":"https://api.github.com/users/yichengq/events{/privacy}","received_events_url":"https://api.github.com/users/yichengq/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":2,"created_at":"2015-06-10T04:44:15Z","updated_at":"2015-06-10T06:28:15Z","closed_at":null,"pull_request":{"url":"https://api.github.com/repos/coreos/etcd/pulls/2944","html_url":"https://github.com/coreos/etcd/pull/2944","diff_url":"https://github.com/coreos/etcd/pull/2944.diff","patch_url":"https://github.com/coreos/etcd/pull/2944.patch"},"body":"ForceGosched() performs bad when GOMAXPROCS>1. When GOMAXPROCS=1, it\r\ncould promise that other goroutines run long enough to the block point\r\nbecause it always yield the processor to other goroutines. But it cannot\r\nyield processor to goroutine running on other processors. So when\r\nGOMAXPROCS>1, the yield may finish when goroutine running on the other\r\nprocessor has not run to block point.\r\n\r\nHere is a test to confirm the case:\r\n\r\n```\r\npackage main\r\n\r\nimport (\r\n\t\"fmt\"\r\n\t\"runtime\"\r\n\t\"testing\"\r\n)\r\n\r\nfunc ForceGosched() {\r\n\t// possibility enough to sched up to 10 go routines.\r\n\tfor i := 0; i < 10000; i++ {\r\n\t\truntime.Gosched()\r\n\t}\r\n}\r\n\r\nvar d int\r\n\r\nfunc loop(c chan struct{}) {\r\n\tfor {\r\n\t\tselect {\r\n\t\tcase <-c:\r\n\t\t\tfor i := 0; i < 1000; i++ {\r\n\t\t\t\tfmt.Sprintf(\"come to time %d\", i)\r\n\t\t\t}\r\n\t\t\td++\r\n\t\t}\r\n\t}\r\n}\r\n\r\nfunc TestLoop(t *testing.T) {\r\n\tc := make(chan struct{}, 1)\r\n\tgo loop(c)\r\n\tc <- struct{}{}\r\n\tForceGosched()\r\n\tif d != 1 {\r\n\t\tt.Fatal(\"d is not incremented\")\r\n\t}\r\n}\r\n```\r\n\r\n`go test -v -race` runs well, but `GOMAXPROCS=2 go test -v -race` fails.\r\n\r\nChange the functionality to waiting for other goroutines to be blocked.\r\n\r\nfixes #2936 #2935 \r\n\r\n/cc @jonboulle "},"comment":{"url":"https://api.github.com/repos/coreos/etcd/issues/comments/110612918","html_url":"https://github.com/coreos/etcd/pull/2944#issuecomment-110612918","issue_url":"https://api.github.com/repos/coreos/etcd/issues/2944","id":110612918,"user":{"login":"yichengq","id":2976232,"avatar_url":"https://avatars.githubusercontent.com/u/2976232?v=3","gravatar_id":"","url":"https://api.github.com/users/yichengq","html_url":"https://github.com/yichengq","followers_url":"https://api.github.com/users/yichengq/followers","following_url":"https://api.github.com/users/yichengq/following{/other_user}","gists_url":"https://api.github.com/users/yichengq/gists{/gist_id}","starred_url":"https://api.github.com/users/yichengq/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/yichengq/subscriptions","organizations_url":"https://api.github.com/users/yichengq/orgs","repos_url":"https://api.github.com/users/yichengq/repos","events_url":"https://api.github.com/users/yichengq/events{/privacy}","received_events_url":"https://api.github.com/users/yichengq/received_events","type":"User","site_admin":false},"created_at":"2015-06-10T06:28:15Z","updated_at":"2015-06-10T06:28:15Z","body":"still dig into the left failure. That failure is not related to this PR in high probability because the failed test doesn't call ForceGosched func."}}