Skip to content

Commit 6ab3d11

Browse files
authored
Merge pull request #497 from KhronosGroup/mkinsner-improve-mutex-wording
Improve wording around buffer mutexes
2 parents f077b1f + 01e0449 commit 6ab3d11

1 file changed

Lines changed: 14 additions & 11 deletions

File tree

adoc/chapters/programming_interface.adoc

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6114,14 +6114,15 @@ if set final data is [code]#nullptr)#.
61146114
[[subsec:mutex]]
61156115
=== Synchronization primitives
61166116

6117-
When the user wants to use the [code]#buffer# simultaneously in the
6118-
<<sycl-runtime>> and their own code (e.g. a multi-threaded mechanism) and wants
6119-
to use manual synchronization without using a [code]#host_accessor#, a
6120-
[code]#std::mutex# can be passed to the [code]#buffer# constructor via the right
6117+
To prevent race conditions between accesses to the host memory owned by a
6118+
[code]#buffer# in the <<sycl-runtime>> (e.g., by accessors) and in host code, it
6119+
is necessary to use manual synchronization through a [code]#host_accessor#, or
6120+
by passing a [code]#std::mutex# to the [code]#buffer# constructor through a
61216121
[code]#property#.
61226122

6123-
The runtime promises to lock the mutex whenever the data is in use and unlock it
6124-
when it no longer needs it.
6123+
When a [code]#buffer# was constructed with a [code]#std::mutex# property, the
6124+
SYCL runtime is required to lock the mutex whenever the data is in use by the
6125+
runtime, and unlock the mutex when the data is not in use by the SYCL runtime.
61256126

61266127
[source,,linenums]
61276128
----
@@ -6131,17 +6132,19 @@ when it no longer needs it.
61316132
sycl::buffer b { shD, { sycl::property::buffer::use_mutex { m } } };
61326133
{
61336134
std::lock_guard lck { m };
6135+
61346136
// User accesses the data
61356137
do_something(shD);
6136-
/* m is unlocked when lck goes out of scope, by normal end of this
6137-
block but also if an exception is thrown for example */
6138+
6139+
/* m is unlocked when lck goes out of scope, either at normal ending of this
6140+
block or if an exception is thrown */
61386141
}
61396142
}
61406143
----
61416144

6142-
When the runtime releases the mutex the user is guaranteed that the data was
6143-
copied back on the shared pointer --- unless the final data destination has been
6144-
changed using the member function [code]#set_final_data()#.
6145+
When the runtime releases the mutex, the user is guaranteed that the data has
6146+
been copied back through the shared pointer --- unless the final data
6147+
destination has been changed using the member function [code]#set_final_data()#.
61456148

61466149

61476150
[[subsec:accessors]]

0 commit comments

Comments
 (0)