Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
las3_pub
/
predictable_parallel_patterns
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Members
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
56e16fcf
authored
Mar 20, 2019
by
FritzFlorian
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix: Spinlock test triggers thread sanitizer.
parent
0599cfdc
Pipeline
#1101
passed with stages
in 2 minutes 12 seconds
Changes
3
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
13 additions
and
9 deletions
+13
-9
.gitlab-ci.yml
+1
-1
lib/pls/src/internal/base/spin_lock.cpp
+2
-0
test/base_tests.cpp
+10
-8
No files found.
.gitlab-ci.yml
View file @
56e16fcf
image
:
"
matrim/cmake-examples:3.10.3
"
image
:
"
flofritz/ci-benchmark-hpx-embb
"
stages
:
stages
:
-
build
-
build
...
...
lib/pls/src/internal/base/spin_lock.cpp
View file @
56e16fcf
...
@@ -11,10 +11,12 @@ namespace pls {
...
@@ -11,10 +11,12 @@ namespace pls {
this_thread
::
yield
();
this_thread
::
yield
();
}
}
}
}
std
::
atomic_thread_fence
(
std
::
memory_order_seq_cst
);
}
}
void
spin_lock
::
unlock
()
{
void
spin_lock
::
unlock
()
{
flag_
.
clear
(
std
::
memory_order_release
);
flag_
.
clear
(
std
::
memory_order_release
);
std
::
atomic_thread_fence
(
std
::
memory_order_seq_cst
);
}
}
}
}
}
}
...
...
test/base_tests.cpp
View file @
56e16fcf
...
@@ -33,23 +33,25 @@ TEST_CASE( "thread state", "[internal/base/thread.h]") {
...
@@ -33,23 +33,25 @@ TEST_CASE( "thread state", "[internal/base/thread.h]") {
REQUIRE
(
base_tests_local_value_two
==
vector
<
int
>
{
1
,
2
});
REQUIRE
(
base_tests_local_value_two
==
vector
<
int
>
{
1
,
2
});
}
}
int
base_tests_shared_counter
;
TEST_CASE
(
"spinlock protects concurrent counter"
,
"[internal/base/spinlock.h]"
)
{
TEST_CASE
(
"spinlock protects concurrent counter"
,
"[internal/base/spinlock.h]"
)
{
constexpr
int
num_iterations
=
100000
;
constexpr
int
num_iterations
=
100000
0
;
int
shared_counter
=
0
;
base_tests_
shared_counter
=
0
;
spin_lock
lock
{};
spin_lock
lock
{};
SECTION
(
"lock can be used by itself"
)
{
SECTION
(
"lock can be used by itself"
)
{
auto
t1
=
start_thread
([
&
]()
{
auto
t1
=
start_thread
([
&
]()
{
for
(
int
i
=
0
;
i
<
num_iterations
;
i
++
)
{
for
(
int
i
=
0
;
i
<
num_iterations
;
i
++
)
{
lock
.
lock
();
lock
.
lock
();
shared_counter
++
;
base_tests_
shared_counter
++
;
lock
.
unlock
();
lock
.
unlock
();
}
}
});
});
auto
t2
=
start_thread
([
&
]()
{
auto
t2
=
start_thread
([
&
]()
{
for
(
int
i
=
0
;
i
<
num_iterations
;
i
++
)
{
for
(
int
i
=
0
;
i
<
num_iterations
;
i
++
)
{
lock
.
lock
();
lock
.
lock
();
shared_counter
--
;
base_tests_
shared_counter
--
;
lock
.
unlock
();
lock
.
unlock
();
}
}
});
});
...
@@ -57,26 +59,26 @@ TEST_CASE( "spinlock protects concurrent counter", "[internal/base/spinlock.h]")
...
@@ -57,26 +59,26 @@ TEST_CASE( "spinlock protects concurrent counter", "[internal/base/spinlock.h]")
t1
.
join
();
t1
.
join
();
t2
.
join
();
t2
.
join
();
REQUIRE
(
shared_counter
==
0
);
REQUIRE
(
base_tests_
shared_counter
==
0
);
}
}
SECTION
(
"lock can be used with std::lock_guard"
)
{
SECTION
(
"lock can be used with std::lock_guard"
)
{
auto
t1
=
start_thread
([
&
]()
{
auto
t1
=
start_thread
([
&
]()
{
for
(
int
i
=
0
;
i
<
num_iterations
;
i
++
)
{
for
(
int
i
=
0
;
i
<
num_iterations
;
i
++
)
{
std
::
lock_guard
<
spin_lock
>
my_lock
{
lock
};
std
::
lock_guard
<
spin_lock
>
my_lock
{
lock
};
shared_counter
++
;
base_tests_
shared_counter
++
;
}
}
});
});
auto
t2
=
start_thread
([
&
]()
{
auto
t2
=
start_thread
([
&
]()
{
for
(
int
i
=
0
;
i
<
num_iterations
;
i
++
)
{
for
(
int
i
=
0
;
i
<
num_iterations
;
i
++
)
{
std
::
lock_guard
<
spin_lock
>
my_lock
{
lock
};
std
::
lock_guard
<
spin_lock
>
my_lock
{
lock
};
shared_counter
--
;
base_tests_
shared_counter
--
;
}
}
});
});
t1
.
join
();
t1
.
join
();
t2
.
join
();
t2
.
join
();
REQUIRE
(
shared_counter
==
0
);
REQUIRE
(
base_tests_
shared_counter
==
0
);
}
}
}
}
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