Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in / Register
Toggle navigation
B
brpc
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Packages
Packages
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
submodule
brpc
Commits
27db3d61
Commit
27db3d61
authored
7 years ago
by
gejun
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Patch svn r35141
parent
94e7df4b
No related merge requests found
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
12 additions
and
6 deletions
+12
-6
bthread_setconcurrency_unittest.cpp
test/bthread_setconcurrency_unittest.cpp
+12
-6
No files found.
test/bthread_setconcurrency_unittest.cpp
View file @
27db3d61
...
...
@@ -40,15 +40,17 @@ TEST(BthreadTest, setconcurrency) {
static
base
::
atomic
<
int
>
*
odd
;
static
base
::
atomic
<
int
>
*
even
;
static
base
::
atomic
<
int
>
nthreads
(
0
);
static
base
::
atomic
<
int
>
nbthreads
(
0
);
static
base
::
atomic
<
int
>
npthreads
(
0
);
static
BAIDU_THREAD_LOCAL
bool
counted
=
false
;
static
base
::
atomic
<
bool
>
stop
(
false
);
static
void
*
odd_thread
(
void
*
)
{
nbthreads
.
fetch_add
(
1
);
while
(
!
stop
)
{
if
(
!
counted
)
{
counted
=
true
;
nthreads
.
fetch_add
(
1
);
n
p
threads
.
fetch_add
(
1
);
}
bthread
::
butex_wake_all
(
even
);
bthread
::
butex_wait
(
odd
,
0
,
NULL
);
...
...
@@ -57,10 +59,11 @@ static void *odd_thread(void *) {
}
static
void
*
even_thread
(
void
*
)
{
nbthreads
.
fetch_add
(
1
);
while
(
!
stop
)
{
if
(
!
counted
)
{
counted
=
true
;
nthreads
.
fetch_add
(
1
);
n
p
threads
.
fetch_add
(
1
);
}
bthread
::
butex_wake_all
(
odd
);
bthread
::
butex_wait
(
even
,
0
,
NULL
);
...
...
@@ -75,7 +78,7 @@ TEST(BthreadTest, setconcurrency_with_running_bthread) {
*
odd
=
0
;
*
even
=
0
;
std
::
vector
<
bthread_t
>
tids
;
const
int
N
=
7
00
;
const
int
N
=
5
00
;
for
(
int
i
=
0
;
i
<
N
;
++
i
)
{
bthread_t
tid
;
bthread_start_background
(
&
tid
,
&
BTHREAD_ATTR_SMALL
,
odd_thread
,
NULL
);
...
...
@@ -87,7 +90,7 @@ TEST(BthreadTest, setconcurrency_with_running_bthread) {
ASSERT_EQ
(
0
,
bthread_setconcurrency
(
i
));
ASSERT_EQ
(
i
,
bthread_getconcurrency
());
}
usleep
(
2
000
*
N
);
usleep
(
1
000
*
N
);
*
odd
=
1
;
*
even
=
1
;
stop
=
true
;
...
...
@@ -97,6 +100,9 @@ TEST(BthreadTest, setconcurrency_with_running_bthread) {
bthread_join
(
tids
[
i
],
NULL
);
}
LOG
(
INFO
)
<<
"All bthreads has quit"
;
ASSERT_EQ
(
N
,
nthreads
);
ASSERT_EQ
(
2
*
N
,
nbthreads
);
// This is not necessarily true, not all workers need to run sth.
//ASSERT_EQ(N, npthreads);
LOG
(
INFO
)
<<
"Touched pthreads="
<<
npthreads
;
}
}
// namespace
This diff is collapsed.
Click to expand it.
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment