-
-
Notifications
You must be signed in to change notification settings - Fork 54
Apple Adventure #1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
+1,351
−14
Closed
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| .DS_Store |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,16 +1,18 @@ | ||
| #define MINICORO_IMPL | ||
| #include "minicoro.h" | ||
| #define C89THREAD_IMPLEMENTATION | ||
| #include "thirdparty/c89thread.h" | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Actually I am trying to support the |
||
|
|
||
| #define CUTE_SYNC_IMPLEMENTATION | ||
| #define CUTE_SYNC_POSIX | ||
| #include "thirdparty/cute_sync.h" | ||
| #include <stdio.h> | ||
|
|
||
| #define NUM_THREADS 4 | ||
| #define NUM_TASKS 100 | ||
| #define NUM_ITERATIONS 500 | ||
| #define EXPECTED_RESULT 2396583362 | ||
|
|
||
| static c89mtx_t mutex; | ||
| static c89thrd_t threads[NUM_THREADS]; | ||
| static cute_mutex_t mutex; | ||
| static cute_thread_t* threads[NUM_THREADS]; | ||
| static mco_coro* tasks[NUM_TASKS]; | ||
|
|
||
| static void fail_mco(const char* message, mco_result res) { | ||
|
|
@@ -61,7 +63,7 @@ int thread_worker(void* data) { | |
| mco_coro* task = NULL; | ||
| int task_id = 0; | ||
|
|
||
| if(c89mtx_lock(&mutex) != c89thrd_success) | ||
| if(!cute_lock(&mutex)) | ||
| fail("Unable to lock mutex"); | ||
| for(int i=0;i<NUM_TASKS;++i) { | ||
| if(tasks[i] != NULL) { | ||
|
|
@@ -71,7 +73,7 @@ int thread_worker(void* data) { | |
| break; | ||
| } | ||
| } | ||
| if(c89mtx_unlock(&mutex) != c89thrd_success) | ||
| if(!cute_unlock(&mutex)) | ||
| fail("Unable to unlock mutex"); | ||
|
|
||
| if(!task) { | ||
|
|
@@ -86,10 +88,10 @@ int thread_worker(void* data) { | |
| switch(mco_status(task)) { | ||
| case MCO_SUSPENDED: { /* Task is not finished yet. */ | ||
| /* Add it back to task list. */ | ||
| if(c89mtx_lock(&mutex) != c89thrd_success) | ||
| if(!cute_lock(&mutex)) | ||
| fail("Unable to lock mutex"); | ||
| tasks[task_id] = task; | ||
| if(c89mtx_unlock(&mutex) != c89thrd_success) | ||
| if(!cute_unlock(&mutex)) | ||
| fail("Unable to unlock mutex"); | ||
| break; | ||
| } | ||
|
|
@@ -121,8 +123,7 @@ int thread_worker(void* data) { | |
|
|
||
| int main() { | ||
| /* Initialize mutex. */ | ||
| if(c89mtx_init(&mutex, c89mtx_plain) != c89thrd_success) | ||
| fail("Failed to create mutex"); | ||
| mutex = cute_mutex_create(); | ||
|
|
||
| /* Create coroutine tasks. */ | ||
| for(int i=0;i<NUM_TASKS;++i) { | ||
|
|
@@ -131,13 +132,14 @@ int main() { | |
|
|
||
| /* Create thread workers. */ | ||
| for(size_t i=0;i<NUM_THREADS;++i) { | ||
| if(c89thrd_create(&threads[i], thread_worker, NULL) != c89thrd_success) | ||
| threads[i] = cute_thread_create(thread_worker, NULL, NULL); | ||
| if (!threads[i]) | ||
| fail("Failed to create a thread"); | ||
| } | ||
|
|
||
| /* Wait all threads to finish. */ | ||
| for(size_t i=0;i<NUM_THREADS;++i) { | ||
| if(c89thrd_join(threads[i], NULL) != c89thrd_success) | ||
| if(!cute_thread_wait(threads[i])) | ||
| fail("Failed to join a thread!"); | ||
| } | ||
|
|
||
|
|
@@ -147,7 +149,7 @@ int main() { | |
| } | ||
|
|
||
| /* Destroy mutex. */ | ||
| c89mtx_destroy(&mutex); | ||
| cute_mutex_destroy(&mutex); | ||
|
|
||
| printf("Multithread test succeeded!\n"); | ||
| return 0; | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Offsetting here will probably make the dummy return address endup in the wrong place. The dummy return address assists debugging as the last function in the backtrace when you put a breakpoint inside a coroutine. The offset should be really on
_mco_makectxto overcome this, just like other platform ifdefs offsets there.