{"action":"created","issue":{"url":"https://api.github.com/repos/panjf2000/ants/issues/5","repository_url":"https://api.github.com/repos/panjf2000/ants","labels_url":"https://api.github.com/repos/panjf2000/ants/issues/5/labels{/name}","comments_url":"https://api.github.com/repos/panjf2000/ants/issues/5/comments","events_url":"https://api.github.com/repos/panjf2000/ants/issues/5/events","html_url":"https://github.com/panjf2000/ants/issues/5","id":346842831,"node_id":"MDU6SXNzdWUzNDY4NDI4MzE=","number":5,"title":"关于 <-p.freeSignal 的疑惑","user":{"login":"pathbox","id":8605102,"node_id":"MDQ6VXNlcjg2MDUxMDI=","avatar_url":"https://avatars1.githubusercontent.com/u/8605102?v=4","gravatar_id":"","url":"https://api.github.com/users/pathbox","html_url":"https://github.com/pathbox","followers_url":"https://api.github.com/users/pathbox/followers","following_url":"https://api.github.com/users/pathbox/following{/other_user}","gists_url":"https://api.github.com/users/pathbox/gists{/gist_id}","starred_url":"https://api.github.com/users/pathbox/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/pathbox/subscriptions","organizations_url":"https://api.github.com/users/pathbox/orgs","repos_url":"https://api.github.com/users/pathbox/repos","events_url":"https://api.github.com/users/pathbox/events{/privacy}","received_events_url":"https://api.github.com/users/pathbox/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":1,"created_at":"2018-08-02T03:09:57Z","updated_at":"2018-08-03T15:32:00Z","closed_at":"2018-08-03T15:32:00Z","author_association":"NONE","body":"Hi,\r\n    我阅读了源码，对 `<-p.freeSignal` 这句代码有疑惑。 这句代码出现在了多个地方，freeSignal 的作用英文注释我是理解的，并且知道在 `putWorker` 中才进行 `p.freeSignal <- sig{}`\r\n\r\n对于下面的代码\r\n```\r\nfunc (p *Pool) getWorker() *Worker {\r\n\tvar w *Worker\r\n\twaiting := false\r\n\r\n\tp.lock.Lock()\r\n\tidleWorkers := p.workers\r\n\tn := len(idleWorkers) - 1\r\n\tif n < 0 { // 说明 pool中没有worker了\r\n\t\twaiting = p.Running() >= p.Cap()\r\n\t} else { // 说明pool中有worker\r\n\t\t<-p.freeSignal      \r\n\t\tw = idleWorkers[n]  \r\n\t\tidleWorkers[n] = nil\r\n\t\tp.workers = idleWorkers[:n]\r\n\t}\r\n\tp.lock.Unlock()\r\n\r\n\r\nfunc (p *Pool) Release() error {\r\n\tp.once.Do(func() { // 保证只释放一次\r\n\t\tp.release <- sig{}\r\n\t\tp.lock.Lock()\r\n\t\tidleWorkers := p.workers\r\n\t\tfor i, w := range idleWorkers {\r\n\t\t\t<-p.freeSignal\r\n\t\t\tw.task <- nil\r\n\t\t\tidleWorkers[i] = nil\r\n\t\t}\r\n\t\tp.workers = nil\r\n\t\tp.lock.Unlock()\r\n\t})\r\n\treturn nil\r\n}\r\n\r\n```\r\n\r\n中的 `<-p.freeSignal`， 那不是要等putWorker触发了才会继续进行吗？如果 putWorker不触发，就一直阻塞在那了，即使 idleWorkers 中可能是有worker的\r\n\r\n可否解释下这边的逻辑？谢谢"},"comment":{"url":"https://api.github.com/repos/panjf2000/ants/issues/comments/410290418","html_url":"https://github.com/panjf2000/ants/issues/5#issuecomment-410290418","issue_url":"https://api.github.com/repos/panjf2000/ants/issues/5","id":410290418,"node_id":"MDEyOklzc3VlQ29tbWVudDQxMDI5MDQxOA==","user":{"login":"panjf2000","id":7496278,"node_id":"MDQ6VXNlcjc0OTYyNzg=","avatar_url":"https://avatars2.githubusercontent.com/u/7496278?v=4","gravatar_id":"","url":"https://api.github.com/users/panjf2000","html_url":"https://github.com/panjf2000","followers_url":"https://api.github.com/users/panjf2000/followers","following_url":"https://api.github.com/users/panjf2000/following{/other_user}","gists_url":"https://api.github.com/users/panjf2000/gists{/gist_id}","starred_url":"https://api.github.com/users/panjf2000/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/panjf2000/subscriptions","organizations_url":"https://api.github.com/users/panjf2000/orgs","repos_url":"https://api.github.com/users/panjf2000/repos","events_url":"https://api.github.com/users/panjf2000/events{/privacy}","received_events_url":"https://api.github.com/users/panjf2000/received_events","type":"User","site_admin":false},"created_at":"2018-08-03T15:32:00Z","updated_at":"2018-08-03T15:32:00Z","author_association":"OWNER","body":"具体问题可以看 #6 "}}
{"actor":{"display_login":"panjf2000"}}