{"action":"created","issue":{"url":"https://api.github.com/repos/chenshuo/recipes/issues/21","repository_url":"https://api.github.com/repos/chenshuo/recipes","labels_url":"https://api.github.com/repos/chenshuo/recipes/issues/21/labels{/name}","comments_url":"https://api.github.com/repos/chenshuo/recipes/issues/21/comments","events_url":"https://api.github.com/repos/chenshuo/recipes/issues/21/events","html_url":"https://github.com/chenshuo/recipes/issues/21","id":353452728,"node_id":"MDU6SXNzdWUzNTM0NTI3Mjg=","number":21,"title":"fix dead lock for thread/test/Counter.cc","user":{"login":"liuyunbin","id":9609295,"node_id":"MDQ6VXNlcjk2MDkyOTU=","avatar_url":"https://avatars3.githubusercontent.com/u/9609295?v=4","gravatar_id":"","url":"https://api.github.com/users/liuyunbin","html_url":"https://github.com/liuyunbin","followers_url":"https://api.github.com/users/liuyunbin/followers","following_url":"https://api.github.com/users/liuyunbin/following{/other_user}","gists_url":"https://api.github.com/users/liuyunbin/gists{/gist_id}","starred_url":"https://api.github.com/users/liuyunbin/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/liuyunbin/subscriptions","organizations_url":"https://api.github.com/users/liuyunbin/orgs","repos_url":"https://api.github.com/users/liuyunbin/repos","events_url":"https://api.github.com/users/liuyunbin/events{/privacy}","received_events_url":"https://api.github.com/users/liuyunbin/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":0,"created_at":"2018-08-23T16:11:57Z","updated_at":"2018-08-23T20:42:41Z","closed_at":"2018-08-23T20:42:41Z","author_association":"NONE","body":"1. 我觉得以下可以解决拷贝赋值运算符的死锁\r\n\r\n```\r\n    Counter& Counter::operator=(const Counter& rhs) {\r\n        if (this == &rhs)\r\n            return *this;\r\n        int64_t value;\r\n        {\r\n               MutexLockGuard lock(rhs.mutex_);\r\n               value = rhs.value_;\r\n        }\r\n        MutexLockGuard lock(mutex_); \r\n        value_ = value;\r\n        return *this;\r\n    }\r\n```\r\n\r\n2. 对于swap函数, 我想用类似的方法处理, 但感觉有问题, 求大神指教. \r\n\r\n```\r\n    void swap(Counter& a, Counter& b) {\r\n        int64_t value; \r\n        {\r\n            MutexLockGuard lock(a.mutex_);\r\n            value = a.value_;\r\n        }\r\n        {\r\n            MutexLockGuard lock(b.mutex_);\r\n            std::swap(value, b.value_);\r\n        }\r\n        MutexLockGuard lock(a.mutex_);\r\n        a.value_ = value;\r\n    }\r\n```"},"comment":{"url":"https://api.github.com/repos/chenshuo/recipes/issues/comments/415564412","html_url":"https://github.com/chenshuo/recipes/issues/21#issuecomment-415564412","issue_url":"https://api.github.com/repos/chenshuo/recipes/issues/21","id":415564412,"node_id":"MDEyOklzc3VlQ29tbWVudDQxNTU2NDQxMg==","user":{"login":"chenshuo","id":231074,"node_id":"MDQ6VXNlcjIzMTA3NA==","avatar_url":"https://avatars1.githubusercontent.com/u/231074?v=4","gravatar_id":"","url":"https://api.github.com/users/chenshuo","html_url":"https://github.com/chenshuo","followers_url":"https://api.github.com/users/chenshuo/followers","following_url":"https://api.github.com/users/chenshuo/following{/other_user}","gists_url":"https://api.github.com/users/chenshuo/gists{/gist_id}","starred_url":"https://api.github.com/users/chenshuo/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/chenshuo/subscriptions","organizations_url":"https://api.github.com/users/chenshuo/orgs","repos_url":"https://api.github.com/users/chenshuo/repos","events_url":"https://api.github.com/users/chenshuo/events{/privacy}","received_events_url":"https://api.github.com/users/chenshuo/received_events","type":"User","site_admin":false},"created_at":"2018-08-23T20:42:41Z","updated_at":"2018-08-23T20:42:41Z","author_association":"OWNER","body":"书第 8 页。\r\n\r\nTake a look at implementations of:\r\nhttps://en.cppreference.com/w/cpp/thread/lock\r\nhttps://en.cppreference.com/w/cpp/thread/scoped_lock"}}
{"actor":{"display_login":"chenshuo"}}