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
Feb 05, 2020
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
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
79 additions
and
10 deletions
+79
-10
app/playground/CMakeLists.txt
+4
-2
app/playground/barrier.cpp
+13
-0
app/playground/barrier.h
+27
-0
app/playground/main.cpp
+35
-8
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)
# 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
)
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_
);
}
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
app/playground/main.cpp
View file @
7c8d7a83
#include <utility>
#include <utility>
#include <cstdio>
#include <cstdio>
#include <thread>
#include "barrier.h"
#include "context_switcher/context_switcher.h"
#include "context_switcher/context_switcher.h"
using
namespace
context_switcher
;
using
namespace
context_switcher
;
using
namespace
std
;
using
namespace
std
;
...
@@ -10,17 +14,40 @@ const size_t STACK_SIZE = 512 * 32;
...
@@ -10,17 +14,40 @@ const size_t STACK_SIZE = 512 * 32;
const
size_t
NUM_STACKS
=
4
;
const
size_t
NUM_STACKS
=
4
;
char
custom_stacks
[
NUM_STACKS
][
STACK_SIZE
];
char
custom_stacks
[
NUM_STACKS
][
STACK_SIZE
];
volatile
int
result
;
int
main
()
{
int
main
()
{
context_switcher
::
continuation
cont_t1
,
cont_main
;
barrier
bar
{
2
};
int
error
=
0
;
auto
t1
=
std
::
thread
([
&
]()
{
while
(
true
)
{
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
;
while
(
true
)
{
while
(
true
)
{
context_switcher
::
continuation
cont
=
enter_context
(
custom_stacks
[
0
],
STACK_SIZE
,
[](
continuation
&&
main_cont
)
{
count
++
;
// main_cont = context_switcher::switch_context(std::move(main_cont));
if
(
count
%
100
==
0
)
{
return
std
::
move
(
main_cont
);
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
);
});
});
}
// cont = context_switcher::switch_context(std::move(cont));
};
return
0
;
return
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