Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
O
osv
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Verlässliche Systemsoftware
projects
osv
Commits
90aa9da8
Commit
90aa9da8
authored
12 years ago
by
Nadav Har'El
Browse files
Options
Downloads
Patches
Plain Diff
Some more lockfree queue testing. No new bugs found this time :-)
parent
a621c261
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
tests/tst-queue-mpsc.hh
+49
-42
49 additions, 42 deletions
tests/tst-queue-mpsc.hh
with
49 additions
and
42 deletions
tests/tst-queue-mpsc.hh
+
49
−
42
View file @
90aa9da8
...
...
@@ -9,39 +9,33 @@
class
test_queue_mpsc
:
public
unit_tests
::
vtest
{
public:
struct
test_threads_data
{
sched
::
thread
*
main
;
sched
::
thread
*
t1
;
bool
t1ok
;
sched
::
thread
*
t2
;
bool
t2ok
;
int
test_ctr
;
struct
info
{
lockfree
::
queue_mpsc
<
int
>
*
q
;
int
len
;
lockfree
::
linked_item
<
int
>
*
items
;
};
void
test_thread_1
(
test_threads_data
&
tt
)
void
push_thread
(
struct
info
*
in
)
{
while
(
tt
.
test_ctr
<
1000
)
{
sched
::
thread
::
wait_until
([
&
]
{
return
(
tt
.
test_ctr
%
2
)
==
0
;
});
++
tt
.
test_ctr
;
if
(
tt
.
t2ok
)
{
tt
.
t2
->
wake
();
}
for
(
int
i
=
0
;
i
<
in
->
len
;
i
++
){
in
->
items
[
i
].
value
=
i
;
in
->
q
->
push
(
&
in
->
items
[
i
]);
}
tt
.
t1ok
=
false
;
tt
.
main
->
wake
();
}
void
test
_thread
_2
(
test_threads_data
&
tt
)
void
pop
_thread
(
struct
info
*
in
)
{
while
(
tt
.
test_ctr
<
1000
)
{
sched
::
thread
::
wait_until
([
&
]
{
return
(
tt
.
test_ctr
%
2
)
==
1
;
});
++
tt
.
test_ctr
;
if
(
tt
.
t1ok
)
{
tt
.
t1
->
wake
();
int
sum
=
0
,
something
=
0
,
nothing
=
0
;
while
(
something
<
in
->
len
){
int
n
=
in
->
q
->
pop
();
if
(
n
<
0
)
nothing
++
;
else
{
something
++
;
sum
+=
n
;
}
}
tt
.
t2ok
=
false
;
tt
.
main
->
wake
(
);
debug
(
fmt
(
"pop_thread saw something %d times, nothing %d times. sum: %d"
)
%
something
%
nothing
%
sum
);
}
void
run
()
...
...
@@ -59,10 +53,8 @@ public:
assert
(
q
.
pop
()
==
7
);
assert
(
q
.
pop
()
==-
1
);
assert
(
q
.
isempty
());
debug
(
"test3"
);
int
len
=
10
;
int
len
=
1000
;
auto
items
=
new
lockfree
::
linked_item
<
int
>
[
len
];
for
(
int
i
=
0
;
i
<
len
;
i
++
){
items
[
i
].
value
=
i
*
i
;
...
...
@@ -75,20 +67,35 @@ public:
assert
(
q
.
pop
()
==-
1
);
assert
(
q
.
isempty
());
delete
[]
items
;
test_threads_data
tt
;
tt
.
main
=
sched
::
thread
::
current
();
tt
.
t1ok
=
tt
.
t2ok
=
true
;
tt
.
t1
=
new
sched
::
thread
([
&
]
{
test_thread_1
(
tt
);
});
tt
.
t2
=
new
sched
::
thread
([
&
]
{
test_thread_2
(
tt
);
});
tt
.
test_ctr
=
0
;
tt
.
t1
->
start
();
tt
.
t2
->
start
();
sched
::
thread
::
wait_until
([
&
]
{
return
tt
.
test_ctr
>=
1000
;
});
tt
.
t1
->
join
();
tt
.
t2
->
join
();
delete
tt
.
t1
;
delete
tt
.
t2
;
// A very basic multi-threaded test - 3 threads pushing, 1 popping
len
=
1000
;
auto
items1
=
new
lockfree
::
linked_item
<
int
>
[
len
];
auto
items2
=
new
lockfree
::
linked_item
<
int
>
[
len
];
auto
items3
=
new
lockfree
::
linked_item
<
int
>
[
len
];
struct
info
info1
=
{
&
q
,
len
,
items1
};
struct
info
info2
=
{
&
q
,
len
,
items2
};
struct
info
info3
=
{
&
q
,
len
,
items3
};
struct
info
infop
=
{
&
q
,
len
*
3
,
nullptr
};
auto
t1
=
new
sched
::
thread
([
&
]
{
push_thread
(
&
info1
);
});
auto
t2
=
new
sched
::
thread
([
&
]
{
push_thread
(
&
info2
);
});
auto
t3
=
new
sched
::
thread
([
&
]
{
push_thread
(
&
info3
);
});
auto
tp
=
new
sched
::
thread
([
&
]
{
pop_thread
(
&
infop
);
});
tp
->
start
();
t1
->
start
();
t2
->
start
();
t3
->
start
();
t1
->
join
();
t2
->
join
();
t3
->
join
();
tp
->
join
();
debug
(
fmt
(
"sum should be %d"
)
%
((
len
-
1
)
*
len
/
2
*
3
));
delete
t1
;
delete
t2
;
delete
t3
;
delete
tp
;
delete
[]
items1
;
delete
[]
items2
;
delete
[]
items3
;
debug
(
"lockfree MPSC queue tests succeeded"
);
}
};
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment