[m-rev.] diff: updates to extras/concurrency

Peter Ross pro at missioncriticalit.com
Tue Mar 4 01:22:25 AEDT 2003


On Sat, Mar 01, 2003 at 04:06:11AM +1100, Fergus Henderson wrote:
> The random numbers there are not properly random.
> You should use the same System.Random value for each call,
> e.g. by defining a class static variable to hold it.
> 

===================================================================


Estimated hours taken: 0.25
Branches: main, release

extras/concurrency/philo2.m:
extras/concurrency/philo3.m:
	Only use one random number generator on the IL backend.

Index: philo2.m
===================================================================
RCS file: /home/mercury1/repository/mercury/extras/concurrency/philo2.m,v
retrieving revision 1.6
diff -u -r1.6 philo2.m
--- philo2.m	28 Feb 2003 15:20:33 -0000	1.6
+++ philo2.m	3 Mar 2003 14:14:02 -0000
@@ -89,6 +89,10 @@
 name(russell	, "Russell").
 name(sartre	, "Sartre").
 
+:- pragma foreign_code("C#", "
+	public static System.Random rng = new System.Random();
+").
+
 :- pred rand_sleep(int::in, io__state::di, io__state::uo) is det.
 :- pragma c_code(rand_sleep(Int::in, IO0::di, IO::uo),
 		[thread_safe, will_not_call_mercury], "{
@@ -101,5 +105,5 @@
 }").
 :- pragma foreign_proc("C#", rand_sleep(Int::in, _IO0::di, _IO::uo),
 		[thread_safe, will_not_call_mercury, promise_pure], "{
-	System.Threading.Thread.Sleep((new System.Random()).Next(Int) * 1000);
+	System.Threading.Thread.Sleep(rng.Next(Int) * 1000);
 }").
Index: philo3.m
===================================================================
RCS file: /home/mercury1/repository/mercury/extras/concurrency/philo3.m,v
retrieving revision 1.3
diff -u -r1.3 philo3.m
--- philo3.m	28 Feb 2003 15:20:33 -0000	1.3
+++ philo3.m	3 Mar 2003 14:14:02 -0000
@@ -76,6 +76,10 @@
 
 %------------------------------------------------------------------------------%
 
+:- pragma foreign_code("C#", "
+	public static System.Random rng = new System.Random();
+").
+
 :- pred rand_sleep(int::in, io__state::di, io__state::uo) is det.
 :- pragma c_code(rand_sleep(Int::in, IO0::di, IO::uo),
 		[thread_safe, will_not_call_mercury], "{
@@ -88,7 +92,7 @@
 }").
 :- pragma foreign_proc("C#", rand_sleep(Int::in, _IO0::di, _IO::uo),
 		[thread_safe, will_not_call_mercury, promise_pure], "{
-	System.Threading.Thread.Sleep((new System.Random()).Next(Int) * 1000);
+	System.Threading.Thread.Sleep(rng.Next(Int) * 1000);
 }").
 
 %------------------------------------------------------------------------------%


--------------------------------------------------------------------------
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