[m-rev.] for review: [PATCH 1/4] Add thread_safe attribute to store procedures.

Peter Wang novalazy at gmail.com
Fri Jul 25 14:17:16 AEST 2014


On Wed, 23 Jul 2014 16:48:00 +1000, Julien Fischer <jfischer at opturion.com> wrote:
> 
> It simple enough:
> 
> - thread safety is an issue for mutvars attached to the I/O state because
>   the I/O state can be split by a call to spawn and in principle both
> threads
>   can access the mutavar.
> 
> - thread safety is not an issue for mutvars attached to other states since
>   the states must be unique and cannot be split by a call to spawn.
>   (The inst of the closure passed to spawn prevents this.)

I will add these comments.  Let me know if you do or don't want
the four patches on the 14.01 branch.

Peter

diff --git a/library/store.m b/library/store.m
index bd93905..991c997 100644
--- a/library/store.m
+++ b/library/store.m
@@ -59,6 +59,11 @@
     % generic_mutvar(T, S):
     % A mutable variable holding a value of type T in store S.
     %
+    % The mutable variable interface is inherently not thread-safe.
+    % It is the programmer's responsibility to synchronise accesses to a
+    % mutable variable from multiple threads where that is possible,
+    % namely variables attached to the I/O state.
+    %
 :- type generic_mutvar(T, S).
 :- type io_mutvar(T) == generic_mutvar(T, io.state).
 :- type store_mutvar(T, S) == generic_mutvar(T, store(S)).
@@ -119,6 +124,11 @@
     %
     % A reference to value of type T in store S.
     %
+    % The reference interface is inherently not thread-safe.
+    % It is the programmer's responsibility to synchronise accesses to a
+    % reference from multiple threads where that is possible,
+    % namely references attached to the I/O state.
+    %
 :- type generic_ref(T, S).
 :- type io_ref(T, S) == generic_ref(T, io.state).
 :- type store_ref(T, S) == generic_ref(T, store(S)).




More information about the reviews mailing list