diff options
Diffstat (limited to 'src/main.c')
| -rw-r--r-- | src/main.c | 32 |
1 files changed, 25 insertions, 7 deletions
| @@ -7,8 +7,9 @@ | |||
| 7 | 7 | ||
| 8 | #include <errno.h> | 8 | #include <errno.h> |
| 9 | #include <error.h> | 9 | #include <error.h> |
| 10 | #include <threads.h> | ||
| 11 | #include <unistd.h> | ||
| 10 | 12 | ||
| 11 | #include <stdio.h> | ||
| 12 | int testcb(void *data) { | 13 | int testcb(void *data) { |
| 13 | if(!data) | 14 | if(!data) |
| 14 | return -1; | 15 | return -1; |
| @@ -17,14 +18,31 @@ int testcb(void *data) { | |||
| 17 | return 0; | 18 | return 0; |
| 18 | } | 19 | } |
| 19 | 20 | ||
| 21 | int consumer(void *cq) { | ||
| 22 | if(!cq) | ||
| 23 | return -1; | ||
| 24 | |||
| 25 | cqueue *rcq = (cqueue*)cq; | ||
| 26 | for(task *tsk = NULL;;) { | ||
| 27 | tsk = cqueue_waitpop(rcq); | ||
| 28 | if(!tsk) | ||
| 29 | thrd_exit(-1); | ||
| 30 | |||
| 31 | task_fire(tsk); | ||
| 32 | } | ||
| 33 | |||
| 34 | return 0; | ||
| 35 | } | ||
| 36 | |||
| 20 | int main() { | 37 | int main() { |
| 21 | // error(1, ENOTSUP, "No main file lol"); | 38 | // error(1, ENOTSUP, "No main file lol"); |
| 22 | 39 | ||
| 23 | threadpool *tp = threadpool_init(2); | 40 | thrd_t thread; |
| 24 | task *tsk = task_init(testcb, "This is some data"); | 41 | cqueue *cq = cqueue_init(mtx_plain); |
| 25 | threadpool_addtask(tp, tsk); | 42 | thrd_create(&thread, consumer, cq); |
| 26 | threadpool_join(tp); | 43 | cqueue_addtask(cq, task_init(testcb, (void*)"This is some data")); |
| 27 | threadpool_free(tp); | 44 | sleep(10); |
| 45 | cqueue_free(cq); | ||
| 28 | 46 | ||
| 29 | return 0; | 47 | return 0; |
| 30 | } \ No newline at end of file | 48 | } \ No newline at end of file |
