Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
R
runtime
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
cython-plus
runtime
Commits
ee1fe514
Commit
ee1fe514
authored
Sep 12, 2022
by
Xavier Thompson
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Use atomic variable for is_finished flag
parent
c72cc5a2
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
5 additions
and
5 deletions
+5
-5
runtime.pxd
runtime.pxd
+5
-5
No files found.
runtime.pxd
View file @
ee1fe514
...
...
@@ -2,7 +2,7 @@
from
libcpp.deque
cimport
deque
from
libcpp.vector
cimport
vector
from
libcpp.atomic
cimport
atomic
from
libcpp.atomic
cimport
atomic
,
memory_order_relaxed
from
libc.stdio
cimport
printf
from
libc.stdlib
cimport
rand
from
posix.unistd
cimport
sysconf
...
...
@@ -27,7 +27,7 @@ cdef inline void * worker_function(void * arg) nogil:
# Wait until a queue becomes available.
sem_wait
(
&
sch
.
num_free_queues
)
# If the scheduler is finished there is nothing to do anymore.
if
sch
.
is_finished
:
if
sch
.
is_finished
.
load
(
memory_order_relaxed
)
:
return
<
void
*>
0
# Pop or steal a queue.
queue
=
worker
.
get_queue
()
...
...
@@ -104,7 +104,7 @@ cdef cypclass Scheduler:
sem_t
num_free_queues
atomic
[
int
]
num_pending_queues
sem_t
is_idle
volatile
bint
is_finished
atomic
[
bint
]
is_finished
int
num_workers
lock
Scheduler
__new__
(
alloc
,
int
num_workers
=
0
):
...
...
@@ -113,7 +113,7 @@ cdef cypclass Scheduler:
self
.
num_workers
=
num_workers
sem_init
(
&
self
.
num_free_queues
,
0
,
0
)
# Initially the scheduler is idle but not finished
self
.
is_finished
=
False
self
.
is_finished
.
store
(
False
,
memory_order_relaxed
)
sem_init
(
&
self
.
is_idle
,
0
,
1
)
self
.
num_pending_queues
.
store
(
0
)
if
pthread_barrier_init
(
&
self
.
barrier
,
NULL
,
num_workers
+
1
):
...
...
@@ -162,7 +162,7 @@ cdef cypclass Scheduler:
# Wait until all current tasks are joined
self
.
join
()
# Signal the worker threads that there is no more work.
self
.
is_finished
=
True
self
.
is_finished
.
store
(
True
,
memory_order_relaxed
)
# Pretend that there are new queues to wake up the workers.
num_free_queues
=
&
self
.
num_free_queues
for
worker
in
self
.
workers
:
...
...
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