FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
mrubyc/sample_c/sample_task_queue_timeout.c at master · mrubyc/mrubyc · GitHub
Uh oh!
There was an error while loading.
Please reload this page
.
mrubyc
/
mrubyc
Public
Notifications
You must be signed in to change notification settings
Fork
87
Star
494
Code
Issues
0
Pull requests
1
Actions
Projects
Wiki
Security and quality
0
Insights
Additional navigation options
Code
Issues
Pull requests
Actions
Projects
Wiki
Security and quality
Insights
Expand file tree
Breadcrumbs
mrubyc
/
sample_c
/
sample_task_queue_timeout.c
Copy path
More file actions
More file actions
Latest commit
History
History
History
53 lines (46 loc) · 1.79 KB
Breadcrumbs
mrubyc
/
sample_c
/
sample_task_queue_timeout.c
Copy path
File metadata and controls
53 lines (46 loc) · 1.79 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
/*
* Task::Queue#pop(timeout_ms:) demo.
*
* Two tasks share a single Task::Queue through the global variable $q:
* - the consumer task creates $q and pops twice with a timeout
* - the producer task sleeps, then pushes a value
*
* The consumer task is created first, so it runs first, creates the queue and
* blocks on its first (40 ms) pop. The producer sleeps 120 ms -- past that
* deadline -- so the first pop times out and returns nil. The consumer then
* issues a second pop with a 2000 ms timeout; the producer's push arrives well
* within that window, so the second pop returns the value.
*
* Expected output:
* consumer: waiting up to 40 ms (expecting timeout)...
* consumer: pop returned nil (timed out)
* consumer: waiting up to 2000 ms for a value...
* producer: pushing 42
* consumer: got 42
*
* The embedded bytecode is generated from the *.rb sources by picorbc:
* picorbc --remove-lv -Btimeout_consumer_bytecode \
* -o sample_task_queue_timeout_consumer.c \
* sample_task_queue_timeout_consumer.rb
* picorbc --remove-lv -Btimeout_producer_bytecode \
* -o sample_task_queue_timeout_producer.c \
* sample_task_queue_timeout_producer.rb
*/
#include
<stdio.h>
#include
<stdlib.h>
#include
"mrubyc.h"
#include
"sample_task_queue_timeout_consumer.c"
#include
"sample_task_queue_timeout_producer.c"
#if
!defined(
MRBC_MEMORY_SIZE
)
#define
MRBC_MEMORY_SIZE
(1024*60)
#endif
static
uint8_t
memory_pool
[
MRBC_MEMORY_SIZE
];
int
main
(
void
)
{
mrbc_init
(
memory_pool
,
MRBC_MEMORY_SIZE
);
// The consumer must run first so that $q exists before the producer pushes.
if
(
mrbc_create_task
(
timeout_consumer_bytecode
,
0
)
==
NULL
)
return
1
;
if
(
mrbc_create_task
(
timeout_producer_bytecode
,
0
)
==
NULL
)
return
1
;
int
ret
=
mrbc_run
();
return
ret
==
1
?
0
:
ret
;
}
Back
|
FazBrowse Home
|
New Git URL