FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
binaryen/test/example/cpp-threads.cpp at waitqueue-api · WebAssembly/binaryen · GitHub
Uh oh!
There was an error while loading.
Please reload this page
.
WebAssembly
/
binaryen
Public
Notifications
You must be signed in to change notification settings
Fork
881
Star
8.6k
Code
Issues
339
Pull requests
220
Discussions
Actions
Projects
Wiki
Security and quality
0
Insights
Additional navigation options
Code
Issues
Pull requests
Discussions
Actions
Projects
Wiki
Security and quality
Insights
Expand file tree
Breadcrumbs
binaryen
/
test
/
example
/
cpp-threads.cpp
Copy path
More file actions
More file actions
Latest commit
History
History
History
60 lines (45 loc) · 1.62 KB
Breadcrumbs
binaryen
/
test
/
example
/
cpp-threads.cpp
Copy path
File metadata and controls
60 lines (45 loc) · 1.62 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
54
55
56
57
58
59
60
//
test multiple uses of the threadPool
#
include
<
cassert
>
#
include
<
iostream
>
#
include
<
thread
>
#
include
<
vector
>
#
include
<
binaryen-c.h
>
int
NUM_THREADS
=
33
;
void
worker
() {
BinaryenModuleRef
module
=
BinaryenModuleCreate
();
//
Create a function type for i32 (i32, i32)
BinaryenType ii_[
2
] = {
BinaryenTypeInt32
(),
BinaryenTypeInt32
()};
BinaryenType ii =
BinaryenTypeCreate
(ii_,
2
);
//
Get the 0 and 1 arguments, and add them
BinaryenExpressionRef x =
BinaryenLocalGet
(
module
,
0
,
BinaryenTypeInt32
()),
y =
BinaryenLocalGet
(
module
,
1
,
BinaryenTypeInt32
());
BinaryenExpressionRef add =
BinaryenBinary
(
module
,
BinaryenAddInt32
(), x, y);
BinaryenExpressionRef ret =
BinaryenReturn
(
module
, add);
//
Create the add function
//
Note: no additional local variables
//
Note: no basic blocks here, we are an AST. The function body is just an
//
expression node.
BinaryenFunctionRef adder =
BinaryenAddFunction
(
module
,
"
adder
"
, ii,
BinaryenTypeInt32
(),
NULL
,
0
, ret);
//
validate it
assert
(
BinaryenModuleValidate
(
module
));
//
optimize it
BinaryenModuleOptimize
(
module
);
assert
(
BinaryenModuleValidate
(
module
));
//
Clean up the module, which owns all the objects we created above
BinaryenModuleDispose
(
module
);
}
int
main
() {
std::vector<std::thread> threads;
std::cout <<
"
create threads...
\n
"
;
for
(
int
i =
0
; i <
NUM_THREADS
; i++) {
threads.
emplace_back
(worker);
}
std::cout <<
"
threads running in parallel...
\n
"
;
std::cout <<
"
waiting for threads to join...
\n
"
;
for
(
auto
& thread : threads) {
thread.
join
();
}
std::cout <<
"
all done.
\n
"
;
return
0
;
}
Back
|
FazBrowse Home
|
New Git URL