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
7c8d7a83
authored
5 years ago
by
FritzFlorian
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
WIP: Add minimal example to trigger tsan bugs.
parent
f347849f
Pipeline
#1401
failed with stages
in 37 seconds
Changes
4
Pipelines
1
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
78 additions
and
9 deletions
+78
-9
app/playground/CMakeLists.txt
+4
-2
app/playground/barrier.cpp
+13
-0
app/playground/barrier.h
+27
-0
app/playground/main.cpp
+34
-7
No files found.
app/playground/CMakeLists.txt
View file @
7c8d7a83
add_executable
(
playground main.cpp
)
add_executable
(
playground
barrier.h barrier.cpp
main.cpp
)
# Example for adding the library to your app (as a cmake project dependency)
target_link_libraries
(
playground context_switcher
)
target_link_libraries
(
playground context_switcher
Threads::Threads
)
This diff is collapsed.
Click to expand it.
app/playground/barrier.cpp
0 → 100644
View file @
7c8d7a83
#include "barrier.h"
barrier
::
barrier
(
const
unsigned
int
count
)
:
barrier_
{}
{
pthread_barrier_init
(
&
barrier_
,
nullptr
,
count
);
}
barrier
::~
barrier
()
{
pthread_barrier_destroy
(
&
barrier_
);
}
void
barrier
::
wait
()
{
pthread_barrier_wait
(
&
barrier_
);
}
This diff is collapsed.
Click to expand it.
app/playground/barrier.h
0 → 100644
View file @
7c8d7a83
#ifndef PLS_BARRIER_H
#define PLS_BARRIER_H
#include <pthread.h>
/**
* Provides standard barrier behaviour.
* `count` threads have to call `wait()` before any of the `wait()` calls returns,
* thus blocking all threads until everyone reached the barrier.
*
* PORTABILITY:
* Current implementation is based on pthreads.
*/
class
barrier
{
pthread_barrier_t
barrier_
;
public
:
explicit
barrier
(
unsigned
int
count
);
~
barrier
();
void
wait
();
};
#endif //PLS_BARRIER_H
This diff is collapsed.
Click to expand it.
app/playground/main.cpp
View file @
7c8d7a83
#include <utility>
#include <cstdio>
#include <thread>
#include "barrier.h"
#include "context_switcher/context_switcher.h"
using
namespace
context_switcher
;
using
namespace
std
;
...
...
@@ -10,17 +14,40 @@ const size_t STACK_SIZE = 512 * 32;
const
size_t
NUM_STACKS
=
4
;
char
custom_stacks
[
NUM_STACKS
][
STACK_SIZE
];
volatile
int
result
;
int
main
()
{
context_switcher
::
continuation
cont_t1
,
cont_main
;
barrier
bar
{
2
};
int
error
=
0
;
auto
t1
=
std
::
thread
([
&
]()
{
while
(
true
)
{
context_switcher
::
continuation
cont
=
enter_context
(
custom_stacks
[
0
],
STACK_SIZE
,
[](
continuation
&&
main_cont
)
{
// main_cont = context_switcher::switch_context(std::move(main_cont));
return
std
::
move
(
main_cont
);
bar
.
wait
();
auto
cont
=
enter_context
(
custom_stacks
[
0
],
STACK_SIZE
,
[
&
](
continuation
&&
cont
)
{
error
++
;
cont_t1
=
std
::
move
(
cont
);
bar
.
wait
();
error
++
;
return
std
::
move
(
cont_main
);
});
}
});
int
count
=
0
;
// cont = context_switcher::switch_context(std::move(cont));
};
while
(
true
)
{
count
++
;
if
(
count
%
100
==
0
)
{
printf
(
"%d
\n
"
,
count
);
}
bar
.
wait
();
auto
cont
=
enter_context
(
custom_stacks
[
1
],
STACK_SIZE
,
[
&
](
continuation
&&
cont
)
{
error
++
;
cont_main
=
std
::
move
(
cont
);
bar
.
wait
();
error
++
;
return
std
::
move
(
cont_t1
);
});
}
return
0
;
}
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