{"action":"created","comment":{"url":"https://api.github.com/repos/cahirwpz/mimiker/pulls/comments/186296454","pull_request_review_id":117849079,"id":186296454,"diff_hunk":"@@ -4,39 +4,82 @@\n #include <thread.h>\n #include <ktest.h>\n \n-static mtx_t mtx = MTX_INITIALIZER(MTX_DEF);\n-static volatile int32_t value;\n+static mtx_t counter_mtx = MTX_INITIALIZER(MTX_DEF);\n+static volatile int32_t counter_value;\n \n-#define N 1000\n-#define T 5\n+#define COUNTER_N 1000\n+#define COUNTER_T 5\n \n-static thread_t *td[T];\n+static thread_t *counter_td[COUNTER_T];\n \n-static void mtx_test_main(void *arg) {\n-  for (size_t i = 0; i < N; i++) {\n-    mtx_lock(&mtx);\n-    value++;\n-    mtx_unlock(&mtx);\n+static void counter_routine(void *arg) {\n+  for (size_t i = 0; i < COUNTER_N; i++) {\n+    mtx_lock(&counter_mtx);\n+    int32_t v = counter_value;\n+    thread_yield();\n+    counter_value = v + 1;\n+    mtx_unlock(&counter_mtx);\n   }\n }\n \n-static int mtx_test(void) {\n-  value = 0;\n+static int mtx_test_counter(void) {\n+  counter_value = 0;\n \n-  td[0] = thread_create(\"td1\", mtx_test_main, NULL);\n-  td[1] = thread_create(\"td2\", mtx_test_main, NULL);\n-  td[2] = thread_create(\"td3\", mtx_test_main, NULL);\n-  td[3] = thread_create(\"td4\", mtx_test_main, NULL);\n-  td[4] = thread_create(\"td5\", mtx_test_main, NULL);\n+  for (int i = 0; i < COUNTER_T; i++) {\n+    char name[20];\n+    snprintf(name, sizeof(name), \"td%d\", i);\n+    counter_td[i] = thread_create(name, counter_routine, NULL);\n+  }\n+\n+  for (int i = 0; i < COUNTER_T; i++)\n+    sched_add(counter_td[i]);\n+  for (int i = 0; i < COUNTER_T; i++)\n+    thread_join(counter_td[i]);\n+\n+  assert(counter_value == COUNTER_N * COUNTER_T);\n+\n+  return KTEST_SUCCESS;\n+}\n+\n+static mtx_t simple_mtx = MTX_INITIALIZER(MTX_DEF);\n+static thread_t *simple_td0;\n+static int simple_status = 0;\n+\n+static void simple_routine(void *arg) {\n+  WITH_NO_PREEMPTION {\n+    simple_status = 1;\n+    mtx_lock(&simple_mtx);\n+  }\n+  WITH_NO_PREEMPTION {\n+    simple_status = 2;","path":"tests/mutex.c","position":68,"original_position":68,"commit_id":"4d28dcc0f3dce3ee730dc470013224d078a3b934","original_commit_id":"94163473d581d550c7b0a0301171243c94a98d3a","user":{"login":"ilikeheaps","id":17334993,"avatar_url":"https://avatars3.githubusercontent.com/u/17334993?v=4","gravatar_id":"","url":"https://api.github.com/users/ilikeheaps","html_url":"https://github.com/ilikeheaps","followers_url":"https://api.github.com/users/ilikeheaps/followers","following_url":"https://api.github.com/users/ilikeheaps/following{/other_user}","gists_url":"https://api.github.com/users/ilikeheaps/gists{/gist_id}","starred_url":"https://api.github.com/users/ilikeheaps/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ilikeheaps/subscriptions","organizations_url":"https://api.github.com/users/ilikeheaps/orgs","repos_url":"https://api.github.com/users/ilikeheaps/repos","events_url":"https://api.github.com/users/ilikeheaps/events{/privacy}","received_events_url":"https://api.github.com/users/ilikeheaps/received_events","type":"User","site_admin":false},"body":"I wish to leave it as it is for consistency. Actually value `2` has its meaning of not being `0`, `1` or `3`. Perhaps changing numbers to some enum:\r\n```\r\nenum status { INITIAL, LOCKING, UNLOCKING, DONE };\r\n```\r\nwould make it more clear?","created_at":"2018-05-06T16:54:27Z","updated_at":"2018-05-06T16:54:27Z","html_url":"https://github.com/cahirwpz/mimiker/pull/427#discussion_r186296454","pull_request_url":"https://api.github.com/repos/cahirwpz/mimiker/pulls/427","author_association":"COLLABORATOR","_links":{"self":{"href":"https://api.github.com/repos/cahirwpz/mimiker/pulls/comments/186296454"},"html":{"href":"https://github.com/cahirwpz/mimiker/pull/427#discussion_r186296454"},"pull_request":{"href":"https://api.github.com/repos/cahirwpz/mimiker/pulls/427"}},"in_reply_to_id":186288155},"pull_request":{"url":"https://api.github.com/repos/cahirwpz/mimiker/pulls/427","id":186126584,"html_url":"https://github.com/cahirwpz/mimiker/pull/427","diff_url":"https://github.com/cahirwpz/mimiker/pull/427.diff","patch_url":"https://github.com/cahirwpz/mimiker/pull/427.patch","issue_url":"https://api.github.com/repos/cahirwpz/mimiker/issues/427","number":427,"state":"open","locked":false,"title":"Improve/fix mutex test","user":{"login":"ilikeheaps","id":17334993,"avatar_url":"https://avatars3.githubusercontent.com/u/17334993?v=4","gravatar_id":"","url":"https://api.github.com/users/ilikeheaps","html_url":"https://github.com/ilikeheaps","followers_url":"https://api.github.com/users/ilikeheaps/followers","following_url":"https://api.github.com/users/ilikeheaps/following{/other_user}","gists_url":"https://api.github.com/users/ilikeheaps/gists{/gist_id}","starred_url":"https://api.github.com/users/ilikeheaps/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ilikeheaps/subscriptions","organizations_url":"https://api.github.com/users/ilikeheaps/orgs","repos_url":"https://api.github.com/users/ilikeheaps/repos","events_url":"https://api.github.com/users/ilikeheaps/events{/privacy}","received_events_url":"https://api.github.com/users/ilikeheaps/received_events","type":"User","site_admin":false},"body":"Current mutex test doesn't fail (or fails rarely) with empty mutex implementation.\r\n* yield CPU while inside the mutex to create some opportunity for failure\r\n* make T parameter (number of threads) easily configurable\r\n* add prefixes to variables to separate tests\r\n* add a very basic test\r\n\r\nThe test parameters could be now significantly decreased (empty mutex implementation fails at N=1 T=2) for faster testing.","created_at":"2018-05-04T23:49:47Z","updated_at":"2018-05-06T16:54:27Z","closed_at":null,"merged_at":null,"merge_commit_sha":"ef74883209802c22be5108e3aba45d5439299b7f","assignee":null,"assignees":[],"requested_reviewers":[],"requested_teams":[],"labels":[{"id":505184827,"url":"https://api.github.com/repos/cahirwpz/mimiker/labels/WIP","name":"WIP","color":"0e8a16","default":false}],"milestone":null,"commits_url":"https://api.github.com/repos/cahirwpz/mimiker/pulls/427/commits","review_comments_url":"https://api.github.com/repos/cahirwpz/mimiker/pulls/427/comments","review_comment_url":"https://api.github.com/repos/cahirwpz/mimiker/pulls/comments{/number}","comments_url":"https://api.github.com/repos/cahirwpz/mimiker/issues/427/comments","statuses_url":"https://api.github.com/repos/cahirwpz/mimiker/statuses/4d28dcc0f3dce3ee730dc470013224d078a3b934","head":{"label":"melouber:mutex-tests","ref":"mutex-tests","sha":"4d28dcc0f3dce3ee730dc470013224d078a3b934","user":{"login":"melouber","id":24853486,"avatar_url":"https://avatars3.githubusercontent.com/u/24853486?v=4","gravatar_id":"","url":"https://api.github.com/users/melouber","html_url":"https://github.com/melouber","followers_url":"https://api.github.com/users/melouber/followers","following_url":"https://api.github.com/users/melouber/following{/other_user}","gists_url":"https://api.github.com/users/melouber/gists{/gist_id}","starred_url":"https://api.github.com/users/melouber/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/melouber/subscriptions","organizations_url":"https://api.github.com/users/melouber/orgs","repos_url":"https://api.github.com/users/melouber/repos","events_url":"https://api.github.com/users/melouber/events{/privacy}","received_events_url":"https://api.github.com/users/melouber/received_events","type":"User","site_admin":false},"repo":{"id":127903109,"name":"mimiker","full_name":"melouber/mimiker","owner":{"login":"melouber","id":24853486,"avatar_url":"https://avatars3.githubusercontent.com/u/24853486?v=4","gravatar_id":"","url":"https://api.github.com/users/melouber","html_url":"https://github.com/melouber","followers_url":"https://api.github.com/users/melouber/followers","following_url":"https://api.github.com/users/melouber/following{/other_user}","gists_url":"https://api.github.com/users/melouber/gists{/gist_id}","starred_url":"https://api.github.com/users/melouber/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/melouber/subscriptions","organizations_url":"https://api.github.com/users/melouber/orgs","repos_url":"https://api.github.com/users/melouber/repos","events_url":"https://api.github.com/users/melouber/events{/privacy}","received_events_url":"https://api.github.com/users/melouber/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/melouber/mimiker","description":"An experiment with implementation of very simple operating system for Malta board","fork":true,"url":"https://api.github.com/repos/melouber/mimiker","forks_url":"https://api.github.com/repos/melouber/mimiker/forks","keys_url":"https://api.github.com/repos/melouber/mimiker/keys{/key_id}","collaborators_url":"https://api.github.com/repos/melouber/mimiker/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/melouber/mimiker/teams","hooks_url":"https://api.github.com/repos/melouber/mimiker/hooks","issue_events_url":"https://api.github.com/repos/melouber/mimiker/issues/events{/number}","events_url":"https://api.github.com/repos/melouber/mimiker/events","assignees_url":"https://api.github.com/repos/melouber/mimiker/assignees{/user}","branches_url":"https://api.github.com/repos/melouber/mimiker/branches{/branch}","tags_url":"https://api.github.com/repos/melouber/mimiker/tags","blobs_url":"https://api.github.com/repos/melouber/mimiker/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/melouber/mimiker/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/melouber/mimiker/git/refs{/sha}","trees_url":"https://api.github.com/repos/melouber/mimiker/git/trees{/sha}","statuses_url":"https://api.github.com/repos/melouber/mimiker/statuses/{sha}","languages_url":"https://api.github.com/repos/melouber/mimiker/languages","stargazers_url":"https://api.github.com/repos/melouber/mimiker/stargazers","contributors_url":"https://api.github.com/repos/melouber/mimiker/contributors","subscribers_url":"https://api.github.com/repos/melouber/mimiker/subscribers","subscription_url":"https://api.github.com/repos/melouber/mimiker/subscription","commits_url":"https://api.github.com/repos/melouber/mimiker/commits{/sha}","git_commits_url":"https://api.github.com/repos/melouber/mimiker/git/commits{/sha}","comments_url":"https://api.github.com/repos/melouber/mimiker/comments{/number}","issue_comment_url":"https://api.github.com/repos/melouber/mimiker/issues/comments{/number}","contents_url":"https://api.github.com/repos/melouber/mimiker/contents/{+path}","compare_url":"https://api.github.com/repos/melouber/mimiker/compare/{base}...{head}","merges_url":"https://api.github.com/repos/melouber/mimiker/merges","archive_url":"https://api.github.com/repos/melouber/mimiker/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/melouber/mimiker/downloads","issues_url":"https://api.github.com/repos/melouber/mimiker/issues{/number}","pulls_url":"https://api.github.com/repos/melouber/mimiker/pulls{/number}","milestones_url":"https://api.github.com/repos/melouber/mimiker/milestones{/number}","notifications_url":"https://api.github.com/repos/melouber/mimiker/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/melouber/mimiker/labels{/name}","releases_url":"https://api.github.com/repos/melouber/mimiker/releases{/id}","deployments_url":"https://api.github.com/repos/melouber/mimiker/deployments","created_at":"2018-04-03T12:15:37Z","updated_at":"2018-04-30T11:33:39Z","pushed_at":"2018-05-06T16:44:49Z","git_url":"git://github.com/melouber/mimiker.git","ssh_url":"git@github.com:melouber/mimiker.git","clone_url":"https://github.com/melouber/mimiker.git","svn_url":"https://github.com/melouber/mimiker","homepage":"","size":2293,"stargazers_count":0,"watchers_count":0,"language":"C","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":"bsd-3-clause","name":"BSD 3-Clause \"New\" or \"Revised\" License","spdx_id":"BSD-3-Clause","url":"https://api.github.com/licenses/bsd-3-clause"},"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"cahirwpz:master","ref":"master","sha":"8c08e981dffdc8113ecc90518668119316ecdfdd","user":{"login":"cahirwpz","id":265236,"avatar_url":"https://avatars3.githubusercontent.com/u/265236?v=4","gravatar_id":"","url":"https://api.github.com/users/cahirwpz","html_url":"https://github.com/cahirwpz","followers_url":"https://api.github.com/users/cahirwpz/followers","following_url":"https://api.github.com/users/cahirwpz/following{/other_user}","gists_url":"https://api.github.com/users/cahirwpz/gists{/gist_id}","starred_url":"https://api.github.com/users/cahirwpz/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/cahirwpz/subscriptions","organizations_url":"https://api.github.com/users/cahirwpz/orgs","repos_url":"https://api.github.com/users/cahirwpz/repos","events_url":"https://api.github.com/users/cahirwpz/events{/privacy}","received_events_url":"https://api.github.com/users/cahirwpz/received_events","type":"User","site_admin":false},"repo":{"id":46346617,"name":"mimiker","full_name":"cahirwpz/mimiker","owner":{"login":"cahirwpz","id":265236,"avatar_url":"https://avatars3.githubusercontent.com/u/265236?v=4","gravatar_id":"","url":"https://api.github.com/users/cahirwpz","html_url":"https://github.com/cahirwpz","followers_url":"https://api.github.com/users/cahirwpz/followers","following_url":"https://api.github.com/users/cahirwpz/following{/other_user}","gists_url":"https://api.github.com/users/cahirwpz/gists{/gist_id}","starred_url":"https://api.github.com/users/cahirwpz/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/cahirwpz/subscriptions","organizations_url":"https://api.github.com/users/cahirwpz/orgs","repos_url":"https://api.github.com/users/cahirwpz/repos","events_url":"https://api.github.com/users/cahirwpz/events{/privacy}","received_events_url":"https://api.github.com/users/cahirwpz/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/cahirwpz/mimiker","description":"An experiment with implementation of very simple operating system for Malta board","fork":false,"url":"https://api.github.com/repos/cahirwpz/mimiker","forks_url":"https://api.github.com/repos/cahirwpz/mimiker/forks","keys_url":"https://api.github.com/repos/cahirwpz/mimiker/keys{/key_id}","collaborators_url":"https://api.github.com/repos/cahirwpz/mimiker/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/cahirwpz/mimiker/teams","hooks_url":"https://api.github.com/repos/cahirwpz/mimiker/hooks","issue_events_url":"https://api.github.com/repos/cahirwpz/mimiker/issues/events{/number}","events_url":"https://api.github.com/repos/cahirwpz/mimiker/events","assignees_url":"https://api.github.com/repos/cahirwpz/mimiker/assignees{/user}","branches_url":"https://api.github.com/repos/cahirwpz/mimiker/branches{/branch}","tags_url":"https://api.github.com/repos/cahirwpz/mimiker/tags","blobs_url":"https://api.github.com/repos/cahirwpz/mimiker/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/cahirwpz/mimiker/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/cahirwpz/mimiker/git/refs{/sha}","trees_url":"https://api.github.com/repos/cahirwpz/mimiker/git/trees{/sha}","statuses_url":"https://api.github.com/repos/cahirwpz/mimiker/statuses/{sha}","languages_url":"https://api.github.com/repos/cahirwpz/mimiker/languages","stargazers_url":"https://api.github.com/repos/cahirwpz/mimiker/stargazers","contributors_url":"https://api.github.com/repos/cahirwpz/mimiker/contributors","subscribers_url":"https://api.github.com/repos/cahirwpz/mimiker/subscribers","subscription_url":"https://api.github.com/repos/cahirwpz/mimiker/subscription","commits_url":"https://api.github.com/repos/cahirwpz/mimiker/commits{/sha}","git_commits_url":"https://api.github.com/repos/cahirwpz/mimiker/git/commits{/sha}","comments_url":"https://api.github.com/repos/cahirwpz/mimiker/comments{/number}","issue_comment_url":"https://api.github.com/repos/cahirwpz/mimiker/issues/comments{/number}","contents_url":"https://api.github.com/repos/cahirwpz/mimiker/contents/{+path}","compare_url":"https://api.github.com/repos/cahirwpz/mimiker/compare/{base}...{head}","merges_url":"https://api.github.com/repos/cahirwpz/mimiker/merges","archive_url":"https://api.github.com/repos/cahirwpz/mimiker/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/cahirwpz/mimiker/downloads","issues_url":"https://api.github.com/repos/cahirwpz/mimiker/issues{/number}","pulls_url":"https://api.github.com/repos/cahirwpz/mimiker/pulls{/number}","milestones_url":"https://api.github.com/repos/cahirwpz/mimiker/milestones{/number}","notifications_url":"https://api.github.com/repos/cahirwpz/mimiker/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/cahirwpz/mimiker/labels{/name}","releases_url":"https://api.github.com/repos/cahirwpz/mimiker/releases{/id}","deployments_url":"https://api.github.com/repos/cahirwpz/mimiker/deployments","created_at":"2015-11-17T12:46:47Z","updated_at":"2018-05-05T15:25:19Z","pushed_at":"2018-05-06T16:44:50Z","git_url":"git://github.com/cahirwpz/mimiker.git","ssh_url":"git@github.com:cahirwpz/mimiker.git","clone_url":"https://github.com/cahirwpz/mimiker.git","svn_url":"https://github.com/cahirwpz/mimiker","homepage":"","size":2237,"stargazers_count":12,"watchers_count":12,"language":"C","has_issues":true,"has_projects":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":21,"mirror_url":null,"archived":false,"open_issues_count":39,"license":{"key":"bsd-3-clause","name":"BSD 3-Clause \"New\" or \"Revised\" License","spdx_id":"BSD-3-Clause","url":"https://api.github.com/licenses/bsd-3-clause"},"forks":21,"open_issues":39,"watchers":12,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/cahirwpz/mimiker/pulls/427"},"html":{"href":"https://github.com/cahirwpz/mimiker/pull/427"},"issue":{"href":"https://api.github.com/repos/cahirwpz/mimiker/issues/427"},"comments":{"href":"https://api.github.com/repos/cahirwpz/mimiker/issues/427/comments"},"review_comments":{"href":"https://api.github.com/repos/cahirwpz/mimiker/pulls/427/comments"},"review_comment":{"href":"https://api.github.com/repos/cahirwpz/mimiker/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/cahirwpz/mimiker/pulls/427/commits"},"statuses":{"href":"https://api.github.com/repos/cahirwpz/mimiker/statuses/4d28dcc0f3dce3ee730dc470013224d078a3b934"}},"author_association":"COLLABORATOR"}}
{"actor":{"display_login":"ilikeheaps"}}