{"action":"created","comment":{"url":"https://api.github.com/repos/BVLC/caffe/pulls/comments/29366872","id":29366872,"diff_hunk":"@@ -0,0 +1,86 @@\n+#include <boost/thread.hpp>\n+#include <string>\n+\n+#include \"caffe/util/blocking_queue.hpp\"\n+\n+namespace caffe {\n+\n+template<typename T>\n+class BlockingQueue<T>::sync {\n+ public:\n+  mutable boost::mutex mutex_;\n+  boost::condition_variable condition_;\n+};\n+\n+template<typename T>\n+BlockingQueue<T>::BlockingQueue()\n+    : sync_(new sync()) {\n+}\n+\n+template<typename T>\n+void BlockingQueue<T>::push(const T& t) {\n+  boost::mutex::scoped_lock lock(sync_->mutex_);\n+  queue_.push(t);\n+  lock.unlock();","path":"src/caffe/util/blocking_queue.cpp","position":24,"original_position":24,"commit_id":"a0a36f87402899f685b0b014d17ed5747b27c659","original_commit_id":"a0a36f87402899f685b0b014d17ed5747b27c659","user":{"login":"flx42","id":3645581,"avatar_url":"https://avatars.githubusercontent.com/u/3645581?v=3","gravatar_id":"","url":"https://api.github.com/users/flx42","html_url":"https://github.com/flx42","followers_url":"https://api.github.com/users/flx42/followers","following_url":"https://api.github.com/users/flx42/following{/other_user}","gists_url":"https://api.github.com/users/flx42/gists{/gist_id}","starred_url":"https://api.github.com/users/flx42/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/flx42/subscriptions","organizations_url":"https://api.github.com/users/flx42/orgs","repos_url":"https://api.github.com/users/flx42/repos","events_url":"https://api.github.com/users/flx42/events{/privacy}","received_events_url":"https://api.github.com/users/flx42/received_events","type":"User","site_admin":false},"body":"Some reference:\r\nhttp://en.cppreference.com/w/cpp/thread/condition_variable/notify_one\r\n\r\n> The notifying thread does not need to hold the lock on the same mutex as the one held by the waiting thread(s); in fact doing so is a pessimization, since the notified thread would immediately block again, waiting for the notifying thread to release the lock. However, some implementations (in particular many implementations of pthreads) recognize this situation and avoid this \"hurry up and wait\" scenario by transferring the waiting thread from the condition variable's queue directly to the queue of the mutex within the notify call, without waking it up.\r\n","created_at":"2015-04-29T18:42:49Z","updated_at":"2015-04-29T18:42:49Z","html_url":"https://github.com/BVLC/caffe/pull/2366#discussion_r29366872","pull_request_url":"https://api.github.com/repos/BVLC/caffe/pulls/2366","_links":{"self":{"href":"https://api.github.com/repos/BVLC/caffe/pulls/comments/29366872"},"html":{"href":"https://github.com/BVLC/caffe/pull/2366#discussion_r29366872"},"pull_request":{"href":"https://api.github.com/repos/BVLC/caffe/pulls/2366"}}},"pull_request":{"url":"https://api.github.com/repos/BVLC/caffe/pulls/2366","id":34113517,"html_url":"https://github.com/BVLC/caffe/pull/2366","diff_url":"https://github.com/BVLC/caffe/pull/2366.diff","patch_url":"https://github.com/BVLC/caffe/pull/2366.patch","issue_url":"https://api.github.com/repos/BVLC/caffe/issues/2366","number":2366,"state":"open","locked":false,"title":"blocking_queue","user":{"login":"cypof","id":921950,"avatar_url":"https://avatars.githubusercontent.com/u/921950?v=3","gravatar_id":"","url":"https://api.github.com/users/cypof","html_url":"https://github.com/cypof","followers_url":"https://api.github.com/users/cypof/followers","following_url":"https://api.github.com/users/cypof/following{/other_user}","gists_url":"https://api.github.com/users/cypof/gists{/gist_id}","starred_url":"https://api.github.com/users/cypof/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/cypof/subscriptions","organizations_url":"https://api.github.com/users/cypof/orgs","repos_url":"https://api.github.com/users/cypof/repos","events_url":"https://api.github.com/users/cypof/events{/privacy}","received_events_url":"https://api.github.com/users/cypof/received_events","type":"User","site_admin":false},"body":"Part of #2351, I could not switch to #2167 because I needed boost::thread forward declared. Also instead of having a max size, I prefer to use queues in pairs: free and full, so that items can be reused when the consumer is done with them. It is particularly useful for GPU memory which is costly to allocate and destroy.","created_at":"2015-04-25T21:33:35Z","updated_at":"2015-04-29T18:42:49Z","closed_at":null,"merged_at":null,"merge_commit_sha":"76b723fe482ca824a63afb33d41a198bb6ceb284","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/BVLC/caffe/pulls/2366/commits","review_comments_url":"https://api.github.com/repos/BVLC/caffe/pulls/2366/comments","review_comment_url":"https://api.github.com/repos/BVLC/caffe/pulls/comments{/number}","comments_url":"https://api.github.com/repos/BVLC/caffe/issues/2366/comments","statuses_url":"https://api.github.com/repos/BVLC/caffe/statuses/a0a36f87402899f685b0b014d17ed5747b27c659","head":{"label":"cypof:blocking_queue","ref":"blocking_queue","sha":"a0a36f87402899f685b0b014d17ed5747b27c659","user":{"login":"cypof","id":921950,"avatar_url":"https://avatars.githubusercontent.com/u/921950?v=3","gravatar_id":"","url":"https://api.github.com/users/cypof","html_url":"https://github.com/cypof","followers_url":"https://api.github.com/users/cypof/followers","following_url":"https://api.github.com/users/cypof/following{/other_user}","gists_url":"https://api.github.com/users/cypof/gists{/gist_id}","starred_url":"https://api.github.com/users/cypof/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/cypof/subscriptions","organizations_url":"https://api.github.com/users/cypof/orgs","repos_url":"https://api.github.com/users/cypof/repos","events_url":"https://api.github.com/users/cypof/events{/privacy}","received_events_url":"https://api.github.com/users/cypof/received_events","type":"User","site_admin":false},"repo":{"id":25275864,"name":"caffe","full_name":"cypof/caffe","owner":{"login":"cypof","id":921950,"avatar_url":"https://avatars.githubusercontent.com/u/921950?v=3","gravatar_id":"","url":"https://api.github.com/users/cypof","html_url":"https://github.com/cypof","followers_url":"https://api.github.com/users/cypof/followers","following_url":"https://api.github.com/users/cypof/following{/other_user}","gists_url":"https://api.github.com/users/cypof/gists{/gist_id}","starred_url":"https://api.github.com/users/cypof/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/cypof/subscriptions","organizations_url":"https://api.github.com/users/cypof/orgs","repos_url":"https://api.github.com/users/cypof/repos","events_url":"https://api.github.com/users/cypof/events{/privacy}","received_events_url":"https://api.github.com/users/cypof/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/cypof/caffe","description":"Caffe: a fast framework for deep learning. For the most recent version checkout the dev branch. For the latest stable release checkout the master branch.","fork":true,"url":"https://api.github.com/repos/cypof/caffe","forks_url":"https://api.github.com/repos/cypof/caffe/forks","keys_url":"https://api.github.com/repos/cypof/caffe/keys{/key_id}","collaborators_url":"https://api.github.com/repos/cypof/caffe/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/cypof/caffe/teams","hooks_url":"https://api.github.com/repos/cypof/caffe/hooks","issue_events_url":"https://api.github.com/repos/cypof/caffe/issues/events{/number}","events_url":"https://api.github.com/repos/cypof/caffe/events","assignees_url":"https://api.github.com/repos/cypof/caffe/assignees{/user}","branches_url":"https://api.github.com/repos/cypof/caffe/branches{/branch}","tags_url":"https://api.github.com/repos/cypof/caffe/tags","blobs_url":"https://api.github.com/repos/cypof/caffe/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/cypof/caffe/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/cypof/caffe/git/refs{/sha}","trees_url":"https://api.github.com/repos/cypof/caffe/git/trees{/sha}","statuses_url":"https://api.github.com/repos/cypof/caffe/statuses/{sha}","languages_url":"https://api.github.com/repos/cypof/caffe/languages","stargazers_url":"https://api.github.com/repos/cypof/caffe/stargazers","contributors_url":"https://api.github.com/repos/cypof/caffe/contributors","subscribers_url":"https://api.github.com/repos/cypof/caffe/subscribers","subscription_url":"https://api.github.com/repos/cypof/caffe/subscription","commits_url":"https://api.github.com/repos/cypof/caffe/commits{/sha}","git_commits_url":"https://api.github.com/repos/cypof/caffe/git/commits{/sha}","comments_url":"https://api.github.com/repos/cypof/caffe/comments{/number}","issue_comment_url":"https://api.github.com/repos/cypof/caffe/issues/comments{/number}","contents_url":"https://api.github.com/repos/cypof/caffe/contents/{+path}","compare_url":"https://api.github.com/repos/cypof/caffe/compare/{base}...{head}","merges_url":"https://api.github.com/repos/cypof/caffe/merges","archive_url":"https://api.github.com/repos/cypof/caffe/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/cypof/caffe/downloads","issues_url":"https://api.github.com/repos/cypof/caffe/issues{/number}","pulls_url":"https://api.github.com/repos/cypof/caffe/pulls{/number}","milestones_url":"https://api.github.com/repos/cypof/caffe/milestones{/number}","notifications_url":"https://api.github.com/repos/cypof/caffe/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/cypof/caffe/labels{/name}","releases_url":"https://api.github.com/repos/cypof/caffe/releases{/id}","created_at":"2014-10-15T22:12:51Z","updated_at":"2015-04-24T17:21:31Z","pushed_at":"2015-04-29T00:20:29Z","git_url":"git://github.com/cypof/caffe.git","ssh_url":"git@github.com:cypof/caffe.git","clone_url":"https://github.com/cypof/caffe.git","svn_url":"https://github.com/cypof/caffe","homepage":"http://caffe.berkeleyvision.org/","size":34192,"stargazers_count":3,"watchers_count":3,"language":"C++","has_issues":false,"has_downloads":true,"has_wiki":true,"has_pages":true,"forks_count":1,"mirror_url":null,"open_issues_count":1,"forks":1,"open_issues":1,"watchers":3,"default_branch":"master"}},"base":{"label":"BVLC:master","ref":"master","sha":"28e8f9ead072aaa2d90460d4e5eabf12f90a16c1","user":{"login":"BVLC","id":6182163,"avatar_url":"https://avatars.githubusercontent.com/u/6182163?v=3","gravatar_id":"","url":"https://api.github.com/users/BVLC","html_url":"https://github.com/BVLC","followers_url":"https://api.github.com/users/BVLC/followers","following_url":"https://api.github.com/users/BVLC/following{/other_user}","gists_url":"https://api.github.com/users/BVLC/gists{/gist_id}","starred_url":"https://api.github.com/users/BVLC/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/BVLC/subscriptions","organizations_url":"https://api.github.com/users/BVLC/orgs","repos_url":"https://api.github.com/users/BVLC/repos","events_url":"https://api.github.com/users/BVLC/events{/privacy}","received_events_url":"https://api.github.com/users/BVLC/received_events","type":"Organization","site_admin":false},"repo":{"id":12791642,"name":"caffe","full_name":"BVLC/caffe","owner":{"login":"BVLC","id":6182163,"avatar_url":"https://avatars.githubusercontent.com/u/6182163?v=3","gravatar_id":"","url":"https://api.github.com/users/BVLC","html_url":"https://github.com/BVLC","followers_url":"https://api.github.com/users/BVLC/followers","following_url":"https://api.github.com/users/BVLC/following{/other_user}","gists_url":"https://api.github.com/users/BVLC/gists{/gist_id}","starred_url":"https://api.github.com/users/BVLC/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/BVLC/subscriptions","organizations_url":"https://api.github.com/users/BVLC/orgs","repos_url":"https://api.github.com/users/BVLC/repos","events_url":"https://api.github.com/users/BVLC/events{/privacy}","received_events_url":"https://api.github.com/users/BVLC/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/BVLC/caffe","description":"Caffe: a fast open framework for deep learning.","fork":false,"url":"https://api.github.com/repos/BVLC/caffe","forks_url":"https://api.github.com/repos/BVLC/caffe/forks","keys_url":"https://api.github.com/repos/BVLC/caffe/keys{/key_id}","collaborators_url":"https://api.github.com/repos/BVLC/caffe/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/BVLC/caffe/teams","hooks_url":"https://api.github.com/repos/BVLC/caffe/hooks","issue_events_url":"https://api.github.com/repos/BVLC/caffe/issues/events{/number}","events_url":"https://api.github.com/repos/BVLC/caffe/events","assignees_url":"https://api.github.com/repos/BVLC/caffe/assignees{/user}","branches_url":"https://api.github.com/repos/BVLC/caffe/branches{/branch}","tags_url":"https://api.github.com/repos/BVLC/caffe/tags","blobs_url":"https://api.github.com/repos/BVLC/caffe/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/BVLC/caffe/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/BVLC/caffe/git/refs{/sha}","trees_url":"https://api.github.com/repos/BVLC/caffe/git/trees{/sha}","statuses_url":"https://api.github.com/repos/BVLC/caffe/statuses/{sha}","languages_url":"https://api.github.com/repos/BVLC/caffe/languages","stargazers_url":"https://api.github.com/repos/BVLC/caffe/stargazers","contributors_url":"https://api.github.com/repos/BVLC/caffe/contributors","subscribers_url":"https://api.github.com/repos/BVLC/caffe/subscribers","subscription_url":"https://api.github.com/repos/BVLC/caffe/subscription","commits_url":"https://api.github.com/repos/BVLC/caffe/commits{/sha}","git_commits_url":"https://api.github.com/repos/BVLC/caffe/git/commits{/sha}","comments_url":"https://api.github.com/repos/BVLC/caffe/comments{/number}","issue_comment_url":"https://api.github.com/repos/BVLC/caffe/issues/comments{/number}","contents_url":"https://api.github.com/repos/BVLC/caffe/contents/{+path}","compare_url":"https://api.github.com/repos/BVLC/caffe/compare/{base}...{head}","merges_url":"https://api.github.com/repos/BVLC/caffe/merges","archive_url":"https://api.github.com/repos/BVLC/caffe/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/BVLC/caffe/downloads","issues_url":"https://api.github.com/repos/BVLC/caffe/issues{/number}","pulls_url":"https://api.github.com/repos/BVLC/caffe/pulls{/number}","milestones_url":"https://api.github.com/repos/BVLC/caffe/milestones{/number}","notifications_url":"https://api.github.com/repos/BVLC/caffe/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/BVLC/caffe/labels{/name}","releases_url":"https://api.github.com/repos/BVLC/caffe/releases{/id}","created_at":"2013-09-12T18:39:48Z","updated_at":"2015-04-29T16:42:34Z","pushed_at":"2015-04-29T05:59:15Z","git_url":"git://github.com/BVLC/caffe.git","ssh_url":"git@github.com:BVLC/caffe.git","clone_url":"https://github.com/BVLC/caffe.git","svn_url":"https://github.com/BVLC/caffe","homepage":"http://caffe.berkeleyvision.org/","size":60606,"stargazers_count":3339,"watchers_count":3339,"language":"C++","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":true,"forks_count":1938,"mirror_url":null,"open_issues_count":334,"forks":1938,"open_issues":334,"watchers":3339,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/BVLC/caffe/pulls/2366"},"html":{"href":"https://github.com/BVLC/caffe/pull/2366"},"issue":{"href":"https://api.github.com/repos/BVLC/caffe/issues/2366"},"comments":{"href":"https://api.github.com/repos/BVLC/caffe/issues/2366/comments"},"review_comments":{"href":"https://api.github.com/repos/BVLC/caffe/pulls/2366/comments"},"review_comment":{"href":"https://api.github.com/repos/BVLC/caffe/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/BVLC/caffe/pulls/2366/commits"},"statuses":{"href":"https://api.github.com/repos/BVLC/caffe/statuses/a0a36f87402899f685b0b014d17ed5747b27c659"}}}}