[m-rev.] Changed mutvar to mvar in extras/concurrency

Ralph Becket rbeck at microsoft.com
Fri May 25 02:37:42 AEST 2001


Estimated hours taken: 0.2

Renamed mutvar.m as mvar.m and renamed the type it exports.
This will avoid confusion with store__mutvar and uses the
same name as its Haskell inspiration.

extras/concurrency/mutvar.m:
	Marked all exported predicates as obsolete.
	Added XXX comment explaining the change.

extras/concurrency/mvar.m:
	Added.
	An identical copy of the original mutvar.m bar the name change.

extras/concurrency/channel.m:
extras/concurrency/philo2.m:
	Replaced references to mutvar with references to mvar.

- Ralph



Index: channel.m
===================================================================
RCS file:
/home/mercury1/repository/mercury/extras/concurrency/channel.m,v
retrieving revision 1.1
diff -u -r1.1 channel.m
--- channel.m	2000/09/08 09:14:54	1.1
+++ channel.m	2001/05/24 16:31:58
@@ -1,5 +1,5 @@
 
%-----------------------------------------------------------------------
----%
-% Copyright (C) 2000 The University of Melbourne.
+% Copyright (C) 2000-2001 The University of Melbourne.
 % This file may only be copied under the terms of the GNU Library
General
 % Public License - see the file COPYING.LIB
 
%-----------------------------------------------------------------------
----%
@@ -7,7 +7,7 @@
 % Main author:	petdr
 % Stability:	low.
 %
-% A mutvar can only contain a single value, a channel on the otherhand
+% A mvar can only contain a single value, a channel on the otherhand
 % provides unbounded buffering.
 %
 % For example a program could consist of 2 worker threads and one
@@ -51,15 +51,15 @@
 
 :- implementation.
 
-:- import_module mutvar.
+:- import_module mvar.
 
 :- type channel(T)
 	--->	channel(
-			mutvar(stream(T)),	% read end
-			mutvar(stream(T))	% write end
+			mvar(stream(T)),	% read end
+			mvar(stream(T))	% write end
 		).
 
-:- type stream(T)  == mutvar(item(T)).
+:- type stream(T)  == mvar(item(T)).
 
 :- type item(T)
 	--->	item(
@@ -68,34 +68,34 @@
 		).
 
 channel__init(channel(Read, Write)) -->
-	mutvar__init(Read),
-	mutvar__init(Write),
-	mutvar__init(Hole),
-	mutvar__put(Read, Hole),
-	mutvar__put(Write, Hole).
+	mvar__init(Read),
+	mvar__init(Write),
+	mvar__init(Hole),
+	mvar__put(Read, Hole),
+	mvar__put(Write, Hole).
 
 channel__put(channel(_Read, Write), Val) -->
-	mutvar__init(NewHole),
-	mutvar__take(Write, OldHole),
-	mutvar__put(Write, NewHole),
-	mutvar__put(OldHole, item(Val, NewHole)).
+	mvar__init(NewHole),
+	mvar__take(Write, OldHole),
+	mvar__put(Write, NewHole),
+	mvar__put(OldHole, item(Val, NewHole)).
 
 channel__take(channel(Read, _Write), Val) -->
-	mutvar__take(Read, Head),
-	mutvar__take(Head, item(Val, NewHead)),
-	mutvar__put(Read, NewHead).
+	mvar__take(Read, Head),
+	mvar__take(Head, item(Val, NewHead)),
+	mvar__put(Read, NewHead).
 
 channel__duplicate(channel(_Read, Write), channel(NewRead, Write)) -->
-	mutvar__init(NewRead),
-	mutvar__take(Write, Hole),
-	mutvar__put(Write, Hole),
-	mutvar__put(NewRead, Hole).
+	mvar__init(NewRead),
+	mvar__take(Write, Hole),
+	mvar__put(Write, Hole),
+	mvar__put(NewRead, Hole).
 
 channel__untake(channel(Read, _Write), Val) -->
-	mutvar__init(NewHead),
-	mutvar__take(Read, Head),
-	mutvar__put(NewHead, item(Val, Head)),
-	mutvar__put(Read, NewHead).
+	mvar__init(NewHead),
+	mvar__take(Read, Head),
+	mvar__put(NewHead, item(Val, Head)),
+	mvar__put(Read, NewHead).
 
 
%-----------------------------------------------------------------------
----%
 
%-----------------------------------------------------------------------
----%
Index: midi_data
===================================================================
RCS file:
/home/mercury1/repository/mercury/extras/concurrency/midi_data,v
retrieving revision 1.1
diff -u -r1.1 midi_data
Binary files /tmp/cvsurIRXk and midi_data differ
Index: mutvar.m
===================================================================
RCS file:
/home/mercury1/repository/mercury/extras/concurrency/mutvar.m,v
retrieving revision 1.2
diff -u -r1.2 mutvar.m
--- mutvar.m	2000/09/14 14:12:28	1.2
+++ mutvar.m	2001/05/24 16:31:58
@@ -14,6 +14,13 @@
 % Access to a mutvar is thread-safe and can be used to synchronize
 % between different threads.
 %
+% XXX This module is now obsolete in the sense that programmers are
+% encouraged to migrate to using mvar.m which is identical in all
+% respects other than its name and corresponding change of name of
+% the exported type.  This was done to avoid confusion with
+% store__mutvar and to better reflect the Haskell origins of the mvar
+% data type.
+%
 
%-----------------------------------------------------------------------
----%
 
 :- module mutvar.
@@ -26,17 +33,20 @@
 
 	% Create an empty mutvar.
 :- pred mutvar__init(mutvar(T)::out, io__state::di, io__state::uo) is
det.
+:- pragma obsolete(mutvar__init/3).
 
 	% Take the contents of the mutvar out leaving the mutvar empty.
 	% If the mutvar is empty, block until some thread fills the
 	% mutvar.
 :- pred mutvar__take(mutvar(T)::in, T::out,
 		io__state::di, io__state::uo) is det.
+:- pragma obsolete(mutvar__take/4).
 
 	% Place the value of type T into an empty mutvar.  If the
 	% mutvar is full block until it becomes empty.
 :- pred mutvar__put(mutvar(T)::in, T::in,
 		io__state::di, io__state::uo) is det.
+:- pragma obsolete(mutvar__put/4).
 
 
%-----------------------------------------------------------------------
----%
 
%-----------------------------------------------------------------------
----%
Index: philo2.m
===================================================================
RCS file:
/home/mercury1/repository/mercury/extras/concurrency/philo2.m,v
retrieving revision 1.1
diff -u -r1.1 philo2.m
--- philo2.m	2000/09/08 09:14:54	1.1
+++ philo2.m	2001/05/24 16:31:58
@@ -1,12 +1,12 @@
 
%-----------------------------------------------------------------------
----%
-% Copyright (C) 2000 The University of Melbourne.
+% Copyright (C) 2000-2001 The University of Melbourne.
 % This file may only be copied under the terms of the GNU Library
General
 % Public License - see the file COPYING.LIB in the Mercury
distribution.
 
%-----------------------------------------------------------------------
----%
 %
 % Main author: petdr (based on code by conway)
 %
-% The classic "Dining Philosophers" problem, to show how to use mutvars
+% The classic "Dining Philosophers" problem, to show how to use mvars
 % to do coroutining.
 %
 
%-----------------------------------------------------------------------
----%
@@ -20,7 +20,7 @@
 
 :- implementation.
 
-:- import_module mutvar, spawn.
+:- import_module mvar, spawn.
 :- import_module bool, list, require, string.
 
 :- type forks
@@ -35,15 +35,15 @@
 	.
 
 main -->
-	mutvar__init(ForkGlob),
-	mutvar__put(ForkGlob, forks(yes, yes, yes, yes, yes)),
+	mvar__init(ForkGlob),
+	mvar__put(ForkGlob, forks(yes, yes, yes, yes, yes)),
 	spawn(philosopher(plato, ForkGlob)),
 	spawn(philosopher(aristotle, ForkGlob)),
 	spawn(philosopher(descartes, ForkGlob)),
 	spawn(philosopher(russell, ForkGlob)),
 	philosopher(sartre, ForkGlob).
 
-:- pred philosopher(philosopher, mutvar(forks),
+:- pred philosopher(philosopher, mvar(forks),
 		io__state, io__state).
 :- mode philosopher(in, in, di, uo) is cc_multi.
 
@@ -52,21 +52,21 @@
 	{ name(Who, Name) },
 	io__format("%s is thinking.\n", [s(Name)]),
 	rand_sleep(5),
-	mutvar__take(ForkGlob, Forks0),
+	mvar__take(ForkGlob, Forks0),
 	io__format("%s is attempting to eat.\n", [s(Name)]),
 	( { forks(Who, Forks0, Forks1) } ->
-		mutvar__put(ForkGlob, Forks1),
+		mvar__put(ForkGlob, Forks1),
 		io__format("%s is eating.\n", [s(Name)]),
 		rand_sleep(10),
-		mutvar__take(ForkGlob, Forks2),
+		mvar__take(ForkGlob, Forks2),
 		( { forks(Who, Forks3, Forks2) } ->
-			mutvar__put(ForkGlob, Forks3)
+			mvar__put(ForkGlob, Forks3)
 		;
 			{ error("all forked up") }
 		)
 	;
 		% Our 2 forks were not available
-		mutvar__put(ForkGlob, Forks0)
+		mvar__put(ForkGlob, Forks0)
 	),
 	philosopher(Who, ForkGlob).
 
Index: spawn.m
===================================================================
RCS file: /home/mercury1/repository/mercury/extras/concurrency/spawn.m,v
retrieving revision 1.6
diff -u -r1.6 spawn.m
--- spawn.m	2000/12/05 02:07:13	1.6
+++ spawn.m	2001/05/24 16:31:58
@@ -1,5 +1,5 @@
 
%-----------------------------------------------------------------------
----%
-% Copyright (C) 2000 The University of Melbourne.
+% Copyright (C) 2000-2001 The University of Melbourne.
 % This file may only be copied under the terms of the GNU Library
General
 % Public License - see the file COPYING.LIB in the Mercury
distribution.
 
%-----------------------------------------------------------------------
----%
@@ -115,7 +115,7 @@
 	/*
 	** How do we ensure that the parent thread doesn't terminate
until
 	** the child thread has finished it's processing?
-	** By the use of mutvars, or leave it up to user?
+	** By the use of mvars, or leave it up to user?
 	*/
 	return TRUE;
   }

--------------------------------------------------------------------------
mercury-reviews mailing list
post:  mercury-reviews at cs.mu.oz.au
administrative address: owner-mercury-reviews at cs.mu.oz.au
unsubscribe: Address: mercury-reviews-request at cs.mu.oz.au Message: unsubscribe
subscribe:   Address: mercury-reviews-request at cs.mu.oz.au Message: subscribe
--------------------------------------------------------------------------



More information about the reviews mailing list