[m-rev.] for review: remove support for `thread_safe' mutable attribute

Julien Fischer juliensf at csse.unimelb.edu.au
Mon Aug 14 16:45:50 AEST 2006


For review by Peter or Ralph (still pending bootcheck)

The following is in response to a thread on a mercury-developers and
also to some discussions in person with Peter Wang and Ralph.  The
problem is that the existing `thread_safe' attribute on mutables is
fairly much not thread safe.  This diff removes the dodgy behaviour,
although it's not ideal as all mutable now share the same global mutex
as other non-thread-safe foreign code.

Estimated hours taken: 1
Branches: main, release

Get rid of the `thread_safe' mutable attribute, since this doesn't actually
make access to a mutable thread safe (in fact it makes them less thread
safe than the `not_thread_safe' version).

By extension this also removes support for the `not_thread_safe' mutable
attribute.

compiler/prog_io.m:
compiler/prog_item.m:
compiler/prog_mutable.m:
 	Remove support for the `thread_safe' mutable attribute.

compiler/make_hlds_passes.m:
 	Remove support for the `thread_safe' mutable attribute.

 	Mark the foreign clauses for `get' predicates for constant
 	mutables as thread safe.

doc/reference_manual.texi:
 	Delete the documentation for the `thread_safe' mutable attribute.

tests/hard_coded/mutable_decl.m:
tests/hard_coded/trace_goal_env_1.m:
tests/hard_coded/trace_goal_env_2.m:
tests/hard_coded/unusual_name_mutable.m:
tests/hard_coded/sub-modules/mutable_child.m:
tests/hard_coded/sub-modules/mutable_grandchild.m:
tests/hard_coded/sub-modules/mutable_parent.m:
 	Conform to the above change.

Index: compiler/make_hlds_passes.m
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/compiler/make_hlds_passes.m,v
retrieving revision 1.46
diff -u -r1.46 make_hlds_passes.m
--- compiler/make_hlds_passes.m	27 Jul 2006 05:01:12 -0000	1.46
+++ compiler/make_hlds_passes.m	14 Aug 2006 06:24:36 -0000
@@ -1204,12 +1204,7 @@
          ),
          set_box_policy(BoxPolicy, Attrs0, Attrs1),

-        set_may_call_mercury(will_not_call_mercury, Attrs1, Attrs2),
-        ( mutable_var_thread_safe(MutAttrs) = thread_safe ->
-            set_thread_safe(thread_safe, Attrs2, Attrs)
-        ;
-            Attrs = Attrs2
-        ),
+        set_may_call_mercury(will_not_call_mercury, Attrs1, Attrs),

          mutable_var_maybe_foreign_names(MutAttrs) = MaybeForeignNames,
          (
@@ -1250,7 +1245,8 @@
              InitSetPredName =
                  mutable_secret_set_pred_sym_name(ModuleName, Name),

-            set_purity(purity_pure, Attrs, ConstantGetAttrs),
+            set_purity(purity_pure, Attrs, ConstantGetAttrs0),
+            set_thread_safe(thread_safe, ConstantGetAttrs0, ConstantGetAttrs),
              ConstantGetClause = pragma(compiler(mutable_decl),
                  foreign_proc(ConstantGetAttrs,
                      mutable_get_pred_sym_name(ModuleName, Name), predicate,
Index: compiler/prog_io.m
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/compiler/prog_io.m,v
retrieving revision 1.266
diff -u -r1.266 prog_io.m
--- compiler/prog_io.m	27 Jul 2006 05:01:20 -0000	1.266
+++ compiler/prog_io.m	14 Aug 2006 06:21:54 -0000
@@ -1887,7 +1887,6 @@

  :- type collected_mutable_attribute
      --->    trailed(trailed)
-    ;       thread_safe(thread_safe)
      ;       foreign_name(foreign_name)
      ;       attach_to_io_state(bool)
      ;       constant(bool).
@@ -1898,10 +1897,8 @@
  parse_mutable_attrs(MutAttrsTerm, MutAttrsResult) :-
      Attributes0 = default_mutable_attributes,
      ConflictingAttributes = [
-        thread_safe(thread_safe) - thread_safe(not_thread_safe),
          trailed(trailed) - trailed(untrailed),
          constant(yes) - trailed(trailed),
-        constant(yes) - thread_safe(not_thread_safe),
          constant(yes) - attach_to_io_state(yes)
      ],
      (
@@ -1933,8 +1930,6 @@
  :- pred process_mutable_attribute(collected_mutable_attribute::in,
      mutable_var_attributes::in, mutable_var_attributes::out) is det.

-process_mutable_attribute(thread_safe(ThreadSafe), !Attributes) :-
-    set_mutable_var_thread_safe(ThreadSafe, !Attributes).
  process_mutable_attribute(trailed(Trailed), !Attributes) :-
      set_mutable_var_trailed(Trailed, !Attributes).
  process_mutable_attribute(foreign_name(ForeignName), !Attributes) :-
@@ -1945,7 +1940,6 @@
      set_mutable_var_constant(Constant, !Attributes),
      (
          Constant = yes,
-        set_mutable_var_thread_safe(thread_safe, !Attributes),
          set_mutable_var_trailed(untrailed, !Attributes),
          set_mutable_var_attach_to_io_state(no, !Attributes)
      ;
@@ -1968,12 +1962,6 @@
              String  = "attach_to_io_state",
              MutAttr = attach_to_io_state(yes)
          ;
-            String = "thread_safe",
-            MutAttr = thread_safe(thread_safe)
-        ;
-            String = "not_thread_safe",
-            MutAttr = thread_safe(not_thread_safe)
-        ;
              String = "constant",
              MutAttr = constant(yes)
          )
Index: compiler/prog_item.m
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/compiler/prog_item.m,v
retrieving revision 1.19
diff -u -r1.19 prog_item.m
--- compiler/prog_item.m	27 Jul 2006 05:01:21 -0000	1.19
+++ compiler/prog_item.m	14 Aug 2006 06:14:00 -0000
@@ -329,16 +329,12 @@

      % Access functions for the `mutable_var_attributes' structure.
      %
-:- func mutable_var_thread_safe(mutable_var_attributes) = thread_safe.
  :- func mutable_var_trailed(mutable_var_attributes) = trailed.
  :- func mutable_var_maybe_foreign_names(mutable_var_attributes)
      = maybe(list(foreign_name)).
  :- func mutable_var_constant(mutable_var_attributes) = bool.
  :- func mutable_var_attach_to_io_state(mutable_var_attributes) = bool.

-:- pred set_mutable_var_thread_safe(thread_safe::in,
-    mutable_var_attributes::in, mutable_var_attributes::out) is det.
-
  :- pred set_mutable_var_trailed(trailed::in,
      mutable_var_attributes::in, mutable_var_attributes::out) is det.

@@ -805,24 +801,20 @@
  :- type mutable_var_attributes
      --->    mutable_var_attributes(
                  mutable_trailed             :: trailed,
-                mutable_thread_safe         :: thread_safe,
                  mutable_foreign_names       :: maybe(list(foreign_name)),
                  mutable_attach_to_io_state  :: bool,
                  mutable_constant            :: bool
              ).

  default_mutable_attributes =
-    mutable_var_attributes(trailed, not_thread_safe, no, no, no).
+    mutable_var_attributes(trailed, no, no, no).

-mutable_var_thread_safe(MVarAttrs) = MVarAttrs ^ mutable_thread_safe.
  mutable_var_trailed(MVarAttrs) = MVarAttrs ^ mutable_trailed.
  mutable_var_maybe_foreign_names(MVarAttrs) = MVarAttrs ^ mutable_foreign_names.
  mutable_var_attach_to_io_state(MVarAttrs) =
      MVarAttrs ^ mutable_attach_to_io_state.
  mutable_var_constant(MVarAttrs) = MVarAttrs ^ mutable_constant.

-set_mutable_var_thread_safe(ThreadSafe, !Attributes) :-
-    !:Attributes = !.Attributes ^ mutable_thread_safe := ThreadSafe.
  set_mutable_var_trailed(Trailed, !Attributes) :-
      !:Attributes = !.Attributes ^ mutable_trailed := Trailed.
  set_mutable_add_foreign_name(ForeignName, !Attributes) :-
Index: compiler/prog_mutable.m
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/compiler/prog_mutable.m,v
retrieving revision 1.12
diff -u -r1.12 prog_mutable.m
--- compiler/prog_mutable.m	12 Jul 2006 02:51:07 -0000	1.12
+++ compiler/prog_mutable.m	14 Aug 2006 05:42:14 -0000
@@ -5,12 +5,12 @@
  % This file may only be copied under the terms of the GNU General
  % Public License - see the file COPYING in the Mercury distribution.
  %-----------------------------------------------------------------------------%
-
+%
  % File: prog_mutable.m.
  % Main authors: rafe, juliensf.
-
+%
  % Utility predicates for dealing with mutable declarations.
-
+%
  %-----------------------------------------------------------------------------%

  :- module parse_tree.prog_mutable.
Index: doc/reference_manual.texi
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/doc/reference_manual.texi,v
retrieving revision 1.365
diff -u -r1.365 reference_manual.texi
--- doc/reference_manual.texi	1 Aug 2006 23:36:56 -0000	1.365
+++ doc/reference_manual.texi	14 Aug 2006 06:26:07 -0000
@@ -4780,12 +4780,6 @@

  @table @asis

- at item @samp{thread_safe}/@samp{not_thread_safe}
-This attribute declares if it is safe for multiple threads to 
-access the mutable concurrently.
-The default, in case none is specified, is @samp{not_thread_safe}.
-(See @ref{Foreign code attributes} for further details.)
-
  @item @samp{trailed}/@samp{untrailed}
  This attribute declares if the implementation should generate code so that
  the effects of @samp{set_varname/1} can be undone on backtracking.
@@ -4813,10 +4807,8 @@
  The @samp{constant} attribute cannot be specified together with
  the @samp{attach_to_io_state} attribute
  (since they disagree on this signature).
-It also cannot be specified together with explicit
- at samp{not_thread_safe} and @samp{trailed} attributes,
-since accesses consisting of all reads are always thread safe
-and the question of whether to trail updates is moot when there are no updates.
+It also cannot be specified together with an explicit @samp{trailed}
+attribute.

  @end table

Index: tests/hard_coded/mutable_decl.m
===================================================================
RCS file: /home/mercury/mercury1/repository/tests/hard_coded/mutable_decl.m,v
retrieving revision 1.1
diff -u -r1.1 mutable_decl.m
--- tests/hard_coded/mutable_decl.m	5 Sep 2005 02:29:59 -0000	1.1
+++ tests/hard_coded/mutable_decl.m	14 Aug 2006 06:28:14 -0000
@@ -27,9 +27,9 @@

  %-----------------------------------------------------------------------------%

-:- mutable(x, int, 0, ground, [thread_safe]).
+:- mutable(x, int, 0, ground, []).

-:- mutable(y, int, 0, ground, [untrailed, thread_safe]).
+:- mutable(y, int, 0, ground, [untrailed]).

  main(!IO) :-
      semipure get_x(X0), impure set_x(X0 + 1),
Index: tests/hard_coded/trace_goal_env_1.m
===================================================================
RCS file: /home/mercury/mercury1/repository/tests/hard_coded/trace_goal_env_1.m,v
retrieving revision 1.1
diff -u -r1.1 trace_goal_env_1.m
--- tests/hard_coded/trace_goal_env_1.m	27 Jul 2006 05:03:45 -0000	1.1
+++ tests/hard_coded/trace_goal_env_1.m	14 Aug 2006 06:27:23 -0000
@@ -11,7 +11,7 @@
  :- import_module int.
  :- import_module string.

-:- mutable(x, int, 0, ground, [untrailed, thread_safe]).
+:- mutable(x, int, 0, ground, [untrailed]).

  main(!IO) :-
  	promise_pure (
Index: tests/hard_coded/trace_goal_env_2.m
===================================================================
RCS file: /home/mercury/mercury1/repository/tests/hard_coded/trace_goal_env_2.m,v
retrieving revision 1.1
diff -u -r1.1 trace_goal_env_2.m
--- tests/hard_coded/trace_goal_env_2.m	27 Jul 2006 05:03:45 -0000	1.1
+++ tests/hard_coded/trace_goal_env_2.m	14 Aug 2006 06:27:40 -0000
@@ -11,7 +11,7 @@
  :- import_module int.
  :- import_module string.

-:- mutable(x, int, 0, ground, [untrailed, thread_safe]).
+:- mutable(x, int, 0, ground, [untrailed]).

  main(!IO) :-
  	promise_pure (
Index: tests/hard_coded/unusual_name_mutable.m
===================================================================
RCS file: /home/mercury/mercury1/repository/tests/hard_coded/unusual_name_mutable.m,v
retrieving revision 1.1
diff -u -r1.1 unusual_name_mutable.m
--- tests/hard_coded/unusual_name_mutable.m	28 Sep 2005 09:02:16 -0000	1.1
+++ tests/hard_coded/unusual_name_mutable.m	14 Aug 2006 06:27:52 -0000
@@ -10,7 +10,7 @@

  :- import_module int.

-:- mutable('123$%^abc 7', int, 42, ground, [untrailed, thread_safe]).
+:- mutable('123$%^abc 7', int, 42, ground, [untrailed]).

  main(!IO) :-
  	promise_pure ( semipure 'get_123$%^abc 7'(X)),
Index: tests/hard_coded/sub-modules/mutable_child.m
===================================================================
RCS file: /home/mercury/mercury1/repository/tests/hard_coded/sub-modules/mutable_child.m,v
retrieving revision 1.2
diff -u -r1.2 mutable_child.m
--- tests/hard_coded/sub-modules/mutable_child.m	21 Feb 2006 05:47:04 -0000	1.2
+++ tests/hard_coded/sub-modules/mutable_child.m	14 Aug 2006 06:28:41 -0000
@@ -9,7 +9,7 @@
  :- implementation.

  :- mutable(child_global, int, 200, ground,
-	[untrailed, thread_safe, attach_to_io_state]).
+	[untrailed, attach_to_io_state]).

  run_child(!IO) :-
  	io.write_string("In child ...\n", !IO),
Index: tests/hard_coded/sub-modules/mutable_grandchild.m
===================================================================
RCS file: /home/mercury/mercury1/repository/tests/hard_coded/sub-modules/mutable_grandchild.m,v
retrieving revision 1.2
diff -u -r1.2 mutable_grandchild.m
--- tests/hard_coded/sub-modules/mutable_grandchild.m	21 Feb 2006 05:47:04 -0000	1.2
+++ tests/hard_coded/sub-modules/mutable_grandchild.m	14 Aug 2006 06:28:48 -0000
@@ -7,7 +7,7 @@
  :- implementation.

  :- mutable(grandchild_global, int, 300, ground,
-	[untrailed, thread_safe, attach_to_io_state]).
+	[untrailed, attach_to_io_state]).

  run_grandchild(!IO) :-
  	io.write_string("In grandchild ...\n", !IO),
Index: tests/hard_coded/sub-modules/mutable_parent.m
===================================================================
RCS file: /home/mercury/mercury1/repository/tests/hard_coded/sub-modules/mutable_parent.m,v
retrieving revision 1.2
diff -u -r1.2 mutable_parent.m
--- tests/hard_coded/sub-modules/mutable_parent.m	21 Feb 2006 05:47:04 -0000	1.2
+++ tests/hard_coded/sub-modules/mutable_parent.m	14 Aug 2006 06:29:12 -0000
@@ -18,7 +18,7 @@
  :- import_module mutable_parent.mutable_child.mutable_grandchild.

  :- mutable(parent_global, int, 100, ground,
-	[untrailed, thread_safe, attach_to_io_state]).
+	[untrailed, attach_to_io_state]).

  main(!IO) :-
  	mutable_parent.run_parent(!IO),

--------------------------------------------------------------------------
mercury-reviews mailing list
Post messages to:       mercury-reviews at csse.unimelb.edu.au
Administrative Queries: owner-mercury-reviews at csse.unimelb.edu.au
Subscriptions:          mercury-reviews-request at csse.unimelb.edu.au
--------------------------------------------------------------------------



More information about the reviews mailing list