Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
T
typon-concurrency
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
typon
typon-concurrency
Commits
d07dee2b
Commit
d07dee2b
authored
May 13, 2022
by
Xavier Thompson
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Revert "deque.hpp: claim stolen slot before reading it"
This reverts commit
eabe2a99
.
parent
eabe2a99
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
13 additions
and
25 deletions
+13
-25
rt/include/typon/core/scheduler.hpp
rt/include/typon/core/scheduler.hpp
+8
-8
rt/include/typon/fundamental/deque.hpp
rt/include/typon/fundamental/deque.hpp
+5
-17
No files found.
rt/include/typon/core/scheduler.hpp
View file @
d07dee2b
...
@@ -32,7 +32,7 @@ namespace typon
...
@@ -32,7 +32,7 @@ namespace typon
std
::
vector
<
std
::
thread
>
_thread
;
std
::
vector
<
std
::
thread
>
_thread
;
std
::
atomic_bool
_done
{
false
};
std
::
atomic_bool
_done
{
false
};
fdt
::
lock_free
::
event_count
<>
_notifyer
;
fdt
::
lock_free
::
event_count
<>
_notifyer
;
const
uint
_
concurrency
;
const
uint
_
parallelism
;
static
Scheduler
&
get
()
noexcept
static
Scheduler
&
get
()
noexcept
{
{
...
@@ -57,13 +57,13 @@ namespace typon
...
@@ -57,13 +57,13 @@ namespace typon
return
get
().
_deque
[
thread_id
].
pop
();
return
get
().
_deque
[
thread_id
].
pop
();
}
}
Scheduler
(
uint
concurrency
)
noexcept
Scheduler
(
uint
parallelism
)
noexcept
:
_deque
(
concurrency
+
1
,
Deque
(
concurrency
+
1
)
)
:
_deque
(
parallelism
+
1
)
,
_
concurrency
(
concurrency
)
,
_
parallelism
(
parallelism
)
{
{
thread_id
=
concurrency
;
thread_id
=
parallelism
;
for
(
uint
id
=
0
;
id
<
concurrency
;
id
++
)
for
(
uint
id
=
0
;
id
<
parallelism
;
id
++
)
{
{
_thread
.
emplace_back
([
this
,
id
]()
{
_thread
.
emplace_back
([
this
,
id
]()
{
thread_id
=
id
;
thread_id
=
id
;
...
@@ -117,9 +117,9 @@ namespace typon
...
@@ -117,9 +117,9 @@ namespace typon
void
explore_task
(
Task
&
task
)
noexcept
void
explore_task
(
Task
&
task
)
noexcept
{
{
for
(
uint
i
=
0
;
i
<
_
concurrency
*
2
+
1
;
i
++
)
for
(
uint
i
=
0
;
i
<
_
parallelism
*
2
+
1
;
i
++
)
{
{
uint
id
=
fdt
::
random
::
random
()
%
_
concurrency
;
uint
id
=
fdt
::
random
::
random
()
%
_
parallelism
;
if
(
id
==
thread_id
)
if
(
id
==
thread_id
)
{
{
task
=
_deque
.
back
().
steal
();
task
=
_deque
.
back
().
steal
();
...
...
rt/include/typon/fundamental/deque.hpp
View file @
d07dee2b
...
@@ -2,7 +2,6 @@
...
@@ -2,7 +2,6 @@
#define TYPON_FUNDAMENTAL_DEQUE_HPP_INCLUDED
#define TYPON_FUNDAMENTAL_DEQUE_HPP_INCLUDED
#include <atomic>
#include <atomic>
#include <bit>
#include <cstdint>
#include <cstdint>
#include <memory>
#include <memory>
#include <type_traits>
#include <type_traits>
...
@@ -33,16 +32,9 @@ namespace typon::fdt::lock_free
...
@@ -33,16 +32,9 @@ namespace typon::fdt::lock_free
std
::
atomic
<
u64
>
_top
{
1
};
std
::
atomic
<
u64
>
_top
{
1
};
std
::
atomic
<
u64
>
_bottom
{
1
};
std
::
atomic
<
u64
>
_bottom
{
1
};
std
::
atomic
<
array_type
*>
_array
;
std
::
atomic
<
array_type
*>
_array
;
const
unsigned
int
_concurrency
;
deque
(
unsigned
int
concurrency
)
noexcept
deque
(
u8
bits
=
2
)
noexcept
:
_array
(
new
array_type
(
std
::
bit_width
(
concurrency
)
+
1
))
:
_array
(
new
array_type
(
bits
))
,
_concurrency
(
concurrency
)
{}
deque
(
const
deque
&
other
)
noexcept
:
_array
(
new
array_type
(
std
::
bit_width
(
other
.
_concurrency
)
+
1
))
,
_concurrency
(
other
.
_concurrency
)
{}
{}
~
deque
()
~
deque
()
...
@@ -55,7 +47,7 @@ namespace typon::fdt::lock_free
...
@@ -55,7 +47,7 @@ namespace typon::fdt::lock_free
u64
bottom
=
_bottom
.
load
(
relaxed
);
u64
bottom
=
_bottom
.
load
(
relaxed
);
u64
top
=
_top
.
load
(
acquire
);
u64
top
=
_top
.
load
(
acquire
);
array_type
*
array
=
_array
.
load
(
relaxed
);
array_type
*
array
=
_array
.
load
(
relaxed
);
if
(
bottom
-
top
>
array
->
capacity
()
-
_concurrency
)
if
(
bottom
-
top
>
array
->
capacity
()
-
1
)
{
{
array
=
array
->
grow
(
top
,
bottom
);
array
=
array
->
grow
(
top
,
bottom
);
_array
.
store
(
array
);
_array
.
store
(
array
);
...
@@ -100,16 +92,12 @@ namespace typon::fdt::lock_free
...
@@ -100,16 +92,12 @@ namespace typon::fdt::lock_free
if
(
top
<
bottom
)
if
(
top
<
bottom
)
{
{
array_type
*
array
=
_array
.
load
(
consume
);
array_type
*
array
=
_array
.
load
(
consume
);
T
x
=
array
->
get
(
top
);
if
(
!
_top
.
compare_exchange_strong
(
top
,
top
+
1
,
seq_cst
,
relaxed
))
if
(
!
_top
.
compare_exchange_strong
(
top
,
top
+
1
,
seq_cst
,
relaxed
))
{
{
return
{
Abort
};
return
{
Abort
};
}
}
// NB: The original algorithm reads the slot before claiming it.
return
{
x
};
// We read it after. To make sure it isn't overwritten, the push
// operation leaves at least as many slots free as there are
// potentially concurrent stealers.
// This also means reading non-atomically is not a data race.
return
{
array
->
get
(
top
)
};
}
}
return
{
Empty
};
return
{
Empty
};
}
}
...
...
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