{"action":"created","comment":{"url":"https://api.github.com/repos/cscenter/hpcourse/pulls/comments/175215473","pull_request_review_id":104719223,"id":175215473,"diff_hunk":"@@ -0,0 +1,139 @@\n+#include <pthread.h>\n+#include <iostream>\n+#include <vector>\n+\n+pthread_t producer;\n+pthread_t consumer;\n+pthread_t consumer_interruptor;\n+\n+pthread_mutex_t mutex;\n+pthread_mutex_t work_done_mutex;\n+\n+pthread_cond_t cond_wait_consumer_start;\n+pthread_cond_t cond_can_consume;\n+pthread_cond_t cond_can_produce;\n+\n+bool consumer_starded = false;\n+bool work_done = false;\n+\n+int data = 0;\n+bool is_data_updated = false;\n+\n+void wait_for_consumer_to_start() {\n+    pthread_mutex_lock(&mutex);\n+    if (!consumer_starded) pthread_cond_wait(&cond_wait_consumer_start, &mutex);\n+    pthread_mutex_unlock(&mutex);\n+}\n+\n+bool is_work_done() {\n+    pthread_mutex_lock(&work_done_mutex);\n+    if (work_done) {\n+        pthread_mutex_unlock(&work_done_mutex);\n+        return true;\n+    }\n+    pthread_mutex_unlock(&work_done_mutex);\n+    return false;\n+\n+}\n+\n+void* producer_routine(void* arg) {\n+    wait_for_consumer_to_start();\n+    std::cout << \"producer started\" << std::endl;\n+\n+    // Read data, loop through each value and update the value, notify consumer, wait for consumer to process\n+    std::cout << \"please enter number of numbers to be proceed\" << std::endl;\n+    int num;\n+    std::cin >> num;\n+    std::cout << \"please enter \" << num << \" numbers\" << std::endl;\n+\n+    for (int i = 0; i < num; i++) {\n+        int new_data;\n+        std::cin >> new_data;\n+        pthread_mutex_lock(&mutex);\n+        if (is_data_updated) pthread_cond_wait(&cond_can_produce, &mutex);\n+        data = new_data;\n+        is_data_updated = true;\n+        std::cout << \"Produced data: \" << data << std::endl;\n+        pthread_cond_signal(&cond_can_consume);\n+        pthread_mutex_unlock(&mutex);\n+    }\n+\n+    pthread_mutex_lock(&work_done_mutex);\n+    work_done = true;\n+    pthread_cond_signal(&cond_can_consume);\n+    pthread_mutex_unlock(&work_done_mutex);\n+\n+    pthread_exit(nullptr);\n+}\n+\n+void* consumer_routine(void* arg) {\n+    // notify about start\n+    pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, nullptr);\n+    std::cout << \"consumer started\" << std::endl;\n+    pthread_mutex_lock(&mutex);\n+    consumer_starded = true;\n+    pthread_cond_broadcast(&cond_wait_consumer_start);\n+    pthread_mutex_unlock(&mutex);\n+\n+    // allocate value for result\n+    auto * result_sum = new int(0);\n+\n+    // for every update issued by producer, read the value and add to sum\n+    while(!is_work_done()) {\n+        pthread_mutex_lock(&mutex);\n+\n+        if (!is_data_updated) pthread_cond_wait(&cond_can_consume, &mutex);","path":"csc/2018/1.Pthread/KoroteevaAN/main.cpp","position":null,"original_position":85,"commit_id":"5ae34ef45eed18641bc8572b61bf4abf4fc6dbd3","original_commit_id":"86b27b4a235619ea7bb4853b521706313de384c5","user":{"login":"pavlin256","id":20248120,"avatar_url":"https://avatars0.githubusercontent.com/u/20248120?v=4","gravatar_id":"","url":"https://api.github.com/users/pavlin256","html_url":"https://github.com/pavlin256","followers_url":"https://api.github.com/users/pavlin256/followers","following_url":"https://api.github.com/users/pavlin256/following{/other_user}","gists_url":"https://api.github.com/users/pavlin256/gists{/gist_id}","starred_url":"https://api.github.com/users/pavlin256/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/pavlin256/subscriptions","organizations_url":"https://api.github.com/users/pavlin256/orgs","repos_url":"https://api.github.com/users/pavlin256/repos","events_url":"https://api.github.com/users/pavlin256/events{/privacy}","received_events_url":"https://api.github.com/users/pavlin256/received_events","type":"User","site_admin":false},"body":"фиксд","created_at":"2018-03-16T21:11:29Z","updated_at":"2018-03-16T21:11:29Z","html_url":"https://github.com/cscenter/hpcourse/pull/189#discussion_r175215473","pull_request_url":"https://api.github.com/repos/cscenter/hpcourse/pulls/189","author_association":"NONE","_links":{"self":{"href":"https://api.github.com/repos/cscenter/hpcourse/pulls/comments/175215473"},"html":{"href":"https://github.com/cscenter/hpcourse/pull/189#discussion_r175215473"},"pull_request":{"href":"https://api.github.com/repos/cscenter/hpcourse/pulls/189"}},"in_reply_to_id":173664997},"pull_request":{"url":"https://api.github.com/repos/cscenter/hpcourse/pulls/189","id":173783485,"html_url":"https://github.com/cscenter/hpcourse/pull/189","diff_url":"https://github.com/cscenter/hpcourse/pull/189.diff","patch_url":"https://github.com/cscenter/hpcourse/pull/189.patch","issue_url":"https://api.github.com/repos/cscenter/hpcourse/issues/189","number":189,"state":"open","locked":false,"title":"HW1 solution","user":{"login":"pavlin256","id":20248120,"avatar_url":"https://avatars0.githubusercontent.com/u/20248120?v=4","gravatar_id":"","url":"https://api.github.com/users/pavlin256","html_url":"https://github.com/pavlin256","followers_url":"https://api.github.com/users/pavlin256/followers","following_url":"https://api.github.com/users/pavlin256/following{/other_user}","gists_url":"https://api.github.com/users/pavlin256/gists{/gist_id}","starred_url":"https://api.github.com/users/pavlin256/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/pavlin256/subscriptions","organizations_url":"https://api.github.com/users/pavlin256/orgs","repos_url":"https://api.github.com/users/pavlin256/repos","events_url":"https://api.github.com/users/pavlin256/events{/privacy}","received_events_url":"https://api.github.com/users/pavlin256/received_events","type":"User","site_admin":false},"body":"","created_at":"2018-03-08T16:28:18Z","updated_at":"2018-03-16T21:11:29Z","closed_at":null,"merged_at":null,"merge_commit_sha":"a3c9bfd1556d5f6e9418c3c09a00ced2f32b801f","assignee":null,"assignees":[],"requested_reviewers":[],"requested_teams":[],"labels":[],"milestone":null,"commits_url":"https://api.github.com/repos/cscenter/hpcourse/pulls/189/commits","review_comments_url":"https://api.github.com/repos/cscenter/hpcourse/pulls/189/comments","review_comment_url":"https://api.github.com/repos/cscenter/hpcourse/pulls/comments{/number}","comments_url":"https://api.github.com/repos/cscenter/hpcourse/issues/189/comments","statuses_url":"https://api.github.com/repos/cscenter/hpcourse/statuses/5ae34ef45eed18641bc8572b61bf4abf4fc6dbd3","head":{"label":"pavlin256:master","ref":"master","sha":"5ae34ef45eed18641bc8572b61bf4abf4fc6dbd3","user":{"login":"pavlin256","id":20248120,"avatar_url":"https://avatars0.githubusercontent.com/u/20248120?v=4","gravatar_id":"","url":"https://api.github.com/users/pavlin256","html_url":"https://github.com/pavlin256","followers_url":"https://api.github.com/users/pavlin256/followers","following_url":"https://api.github.com/users/pavlin256/following{/other_user}","gists_url":"https://api.github.com/users/pavlin256/gists{/gist_id}","starred_url":"https://api.github.com/users/pavlin256/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/pavlin256/subscriptions","organizations_url":"https://api.github.com/users/pavlin256/orgs","repos_url":"https://api.github.com/users/pavlin256/repos","events_url":"https://api.github.com/users/pavlin256/events{/privacy}","received_events_url":"https://api.github.com/users/pavlin256/received_events","type":"User","site_admin":false},"repo":{"id":124138015,"name":"hpcourse","full_name":"pavlin256/hpcourse","owner":{"login":"pavlin256","id":20248120,"avatar_url":"https://avatars0.githubusercontent.com/u/20248120?v=4","gravatar_id":"","url":"https://api.github.com/users/pavlin256","html_url":"https://github.com/pavlin256","followers_url":"https://api.github.com/users/pavlin256/followers","following_url":"https://api.github.com/users/pavlin256/following{/other_user}","gists_url":"https://api.github.com/users/pavlin256/gists{/gist_id}","starred_url":"https://api.github.com/users/pavlin256/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/pavlin256/subscriptions","organizations_url":"https://api.github.com/users/pavlin256/orgs","repos_url":"https://api.github.com/users/pavlin256/repos","events_url":"https://api.github.com/users/pavlin256/events{/privacy}","received_events_url":"https://api.github.com/users/pavlin256/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/pavlin256/hpcourse","description":"Project is aimed to store student's practical works on high performance computing course","fork":true,"url":"https://api.github.com/repos/pavlin256/hpcourse","forks_url":"https://api.github.com/repos/pavlin256/hpcourse/forks","keys_url":"https://api.github.com/repos/pavlin256/hpcourse/keys{/key_id}","collaborators_url":"https://api.github.com/repos/pavlin256/hpcourse/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/pavlin256/hpcourse/teams","hooks_url":"https://api.github.com/repos/pavlin256/hpcourse/hooks","issue_events_url":"https://api.github.com/repos/pavlin256/hpcourse/issues/events{/number}","events_url":"https://api.github.com/repos/pavlin256/hpcourse/events","assignees_url":"https://api.github.com/repos/pavlin256/hpcourse/assignees{/user}","branches_url":"https://api.github.com/repos/pavlin256/hpcourse/branches{/branch}","tags_url":"https://api.github.com/repos/pavlin256/hpcourse/tags","blobs_url":"https://api.github.com/repos/pavlin256/hpcourse/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/pavlin256/hpcourse/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/pavlin256/hpcourse/git/refs{/sha}","trees_url":"https://api.github.com/repos/pavlin256/hpcourse/git/trees{/sha}","statuses_url":"https://api.github.com/repos/pavlin256/hpcourse/statuses/{sha}","languages_url":"https://api.github.com/repos/pavlin256/hpcourse/languages","stargazers_url":"https://api.github.com/repos/pavlin256/hpcourse/stargazers","contributors_url":"https://api.github.com/repos/pavlin256/hpcourse/contributors","subscribers_url":"https://api.github.com/repos/pavlin256/hpcourse/subscribers","subscription_url":"https://api.github.com/repos/pavlin256/hpcourse/subscription","commits_url":"https://api.github.com/repos/pavlin256/hpcourse/commits{/sha}","git_commits_url":"https://api.github.com/repos/pavlin256/hpcourse/git/commits{/sha}","comments_url":"https://api.github.com/repos/pavlin256/hpcourse/comments{/number}","issue_comment_url":"https://api.github.com/repos/pavlin256/hpcourse/issues/comments{/number}","contents_url":"https://api.github.com/repos/pavlin256/hpcourse/contents/{+path}","compare_url":"https://api.github.com/repos/pavlin256/hpcourse/compare/{base}...{head}","merges_url":"https://api.github.com/repos/pavlin256/hpcourse/merges","archive_url":"https://api.github.com/repos/pavlin256/hpcourse/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/pavlin256/hpcourse/downloads","issues_url":"https://api.github.com/repos/pavlin256/hpcourse/issues{/number}","pulls_url":"https://api.github.com/repos/pavlin256/hpcourse/pulls{/number}","milestones_url":"https://api.github.com/repos/pavlin256/hpcourse/milestones{/number}","notifications_url":"https://api.github.com/repos/pavlin256/hpcourse/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/pavlin256/hpcourse/labels{/name}","releases_url":"https://api.github.com/repos/pavlin256/hpcourse/releases{/id}","deployments_url":"https://api.github.com/repos/pavlin256/hpcourse/deployments","created_at":"2018-03-06T21:01:47Z","updated_at":"2018-03-16T21:10:03Z","pushed_at":"2018-03-16T21:10:02Z","git_url":"git://github.com/pavlin256/hpcourse.git","ssh_url":"git@github.com:pavlin256/hpcourse.git","clone_url":"https://github.com/pavlin256/hpcourse.git","svn_url":"https://github.com/pavlin256/hpcourse","homepage":null,"size":12456,"stargazers_count":0,"watchers_count":0,"language":"Java","has_issues":false,"has_projects":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"archived":false,"open_issues_count":0,"license":{"key":"gpl-2.0","name":"GNU General Public License v2.0","spdx_id":"GPL-2.0","url":"https://api.github.com/licenses/gpl-2.0"},"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"cscenter:master","ref":"master","sha":"2ea6bbd1cf9205ab6d833519978f046f29e68b0b","user":{"login":"cscenter","id":5622041,"avatar_url":"https://avatars3.githubusercontent.com/u/5622041?v=4","gravatar_id":"","url":"https://api.github.com/users/cscenter","html_url":"https://github.com/cscenter","followers_url":"https://api.github.com/users/cscenter/followers","following_url":"https://api.github.com/users/cscenter/following{/other_user}","gists_url":"https://api.github.com/users/cscenter/gists{/gist_id}","starred_url":"https://api.github.com/users/cscenter/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/cscenter/subscriptions","organizations_url":"https://api.github.com/users/cscenter/orgs","repos_url":"https://api.github.com/users/cscenter/repos","events_url":"https://api.github.com/users/cscenter/events{/privacy}","received_events_url":"https://api.github.com/users/cscenter/received_events","type":"Organization","site_admin":false},"repo":{"id":34339216,"name":"hpcourse","full_name":"cscenter/hpcourse","owner":{"login":"cscenter","id":5622041,"avatar_url":"https://avatars3.githubusercontent.com/u/5622041?v=4","gravatar_id":"","url":"https://api.github.com/users/cscenter","html_url":"https://github.com/cscenter","followers_url":"https://api.github.com/users/cscenter/followers","following_url":"https://api.github.com/users/cscenter/following{/other_user}","gists_url":"https://api.github.com/users/cscenter/gists{/gist_id}","starred_url":"https://api.github.com/users/cscenter/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/cscenter/subscriptions","organizations_url":"https://api.github.com/users/cscenter/orgs","repos_url":"https://api.github.com/users/cscenter/repos","events_url":"https://api.github.com/users/cscenter/events{/privacy}","received_events_url":"https://api.github.com/users/cscenter/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/cscenter/hpcourse","description":"Project is aimed to store student's practical works on high performance computing course","fork":false,"url":"https://api.github.com/repos/cscenter/hpcourse","forks_url":"https://api.github.com/repos/cscenter/hpcourse/forks","keys_url":"https://api.github.com/repos/cscenter/hpcourse/keys{/key_id}","collaborators_url":"https://api.github.com/repos/cscenter/hpcourse/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/cscenter/hpcourse/teams","hooks_url":"https://api.github.com/repos/cscenter/hpcourse/hooks","issue_events_url":"https://api.github.com/repos/cscenter/hpcourse/issues/events{/number}","events_url":"https://api.github.com/repos/cscenter/hpcourse/events","assignees_url":"https://api.github.com/repos/cscenter/hpcourse/assignees{/user}","branches_url":"https://api.github.com/repos/cscenter/hpcourse/branches{/branch}","tags_url":"https://api.github.com/repos/cscenter/hpcourse/tags","blobs_url":"https://api.github.com/repos/cscenter/hpcourse/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/cscenter/hpcourse/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/cscenter/hpcourse/git/refs{/sha}","trees_url":"https://api.github.com/repos/cscenter/hpcourse/git/trees{/sha}","statuses_url":"https://api.github.com/repos/cscenter/hpcourse/statuses/{sha}","languages_url":"https://api.github.com/repos/cscenter/hpcourse/languages","stargazers_url":"https://api.github.com/repos/cscenter/hpcourse/stargazers","contributors_url":"https://api.github.com/repos/cscenter/hpcourse/contributors","subscribers_url":"https://api.github.com/repos/cscenter/hpcourse/subscribers","subscription_url":"https://api.github.com/repos/cscenter/hpcourse/subscription","commits_url":"https://api.github.com/repos/cscenter/hpcourse/commits{/sha}","git_commits_url":"https://api.github.com/repos/cscenter/hpcourse/git/commits{/sha}","comments_url":"https://api.github.com/repos/cscenter/hpcourse/comments{/number}","issue_comment_url":"https://api.github.com/repos/cscenter/hpcourse/issues/comments{/number}","contents_url":"https://api.github.com/repos/cscenter/hpcourse/contents/{+path}","compare_url":"https://api.github.com/repos/cscenter/hpcourse/compare/{base}...{head}","merges_url":"https://api.github.com/repos/cscenter/hpcourse/merges","archive_url":"https://api.github.com/repos/cscenter/hpcourse/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/cscenter/hpcourse/downloads","issues_url":"https://api.github.com/repos/cscenter/hpcourse/issues{/number}","pulls_url":"https://api.github.com/repos/cscenter/hpcourse/pulls{/number}","milestones_url":"https://api.github.com/repos/cscenter/hpcourse/milestones{/number}","notifications_url":"https://api.github.com/repos/cscenter/hpcourse/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/cscenter/hpcourse/labels{/name}","releases_url":"https://api.github.com/repos/cscenter/hpcourse/releases{/id}","deployments_url":"https://api.github.com/repos/cscenter/hpcourse/deployments","created_at":"2015-04-21T16:36:38Z","updated_at":"2018-02-24T10:21:09Z","pushed_at":"2018-03-16T21:10:03Z","git_url":"git://github.com/cscenter/hpcourse.git","ssh_url":"git@github.com:cscenter/hpcourse.git","clone_url":"https://github.com/cscenter/hpcourse.git","svn_url":"https://github.com/cscenter/hpcourse","homepage":null,"size":12488,"stargazers_count":2,"watchers_count":2,"language":"Java","has_issues":true,"has_projects":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":100,"mirror_url":null,"archived":false,"open_issues_count":4,"license":{"key":"gpl-2.0","name":"GNU General Public License v2.0","spdx_id":"GPL-2.0","url":"https://api.github.com/licenses/gpl-2.0"},"forks":100,"open_issues":4,"watchers":2,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/cscenter/hpcourse/pulls/189"},"html":{"href":"https://github.com/cscenter/hpcourse/pull/189"},"issue":{"href":"https://api.github.com/repos/cscenter/hpcourse/issues/189"},"comments":{"href":"https://api.github.com/repos/cscenter/hpcourse/issues/189/comments"},"review_comments":{"href":"https://api.github.com/repos/cscenter/hpcourse/pulls/189/comments"},"review_comment":{"href":"https://api.github.com/repos/cscenter/hpcourse/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/cscenter/hpcourse/pulls/189/commits"},"statuses":{"href":"https://api.github.com/repos/cscenter/hpcourse/statuses/5ae34ef45eed18641bc8572b61bf4abf4fc6dbd3"}},"author_association":"NONE"}}
{"actor":{"display_login":"pavlin256"}}