[m-dev.] response to fjh's review of the parallelism changes

Thomas Charles CONWAY conway at cs.mu.OZ.AU
Wed Jun 3 15:46:42 AEST 1998


> Various places, e.g. mercury_spinlock.[ch], still use #ifdef PARALLEL.
> Some other places use MR_THREAD_SAFE.

Apart from mercury_spinlock.{c,h} there was only one occurence
which I fixed. the spinlock files are dead code, and I will remove
these files altogether.

Here's the diff relative to the previous changes.

Thomas
-- 
Thomas Conway <conway at cs.mu.oz.au>
Nail here [] for new monitor.  )O+

diff -u -r bak/mercury/runtime/mercury_engine.c mercury/runtime/mercury_engine.c
--- bak/mercury/runtime/mercury_engine.c	Fri May 22 10:01:24 1998
+++ mercury/runtime/mercury_engine.c	Wed Jun  3 14:16:37 1998
@@ -94,9 +94,14 @@
 
 /*---------------------------------------------------------------------------*/
 
+/*
+** finalize_engine should release any resources used within the
+** engine structure (but not the engine structure itself).
+** Currently, it doesn't need to realease any.
+*/
+
 void finalize_engine(MercuryEngine *eng)
 {
-	
 }
 
 /*---------------------------------------------------------------------------*/
diff -u -r bak/mercury/runtime/mercury_heap.h mercury/runtime/mercury_heap.h
--- bak/mercury/runtime/mercury_heap.h	Fri May 22 10:01:36 1998
+++ mercury/runtime/mercury_heap.h	Mon Jun  1 11:23:55 1998
@@ -104,18 +104,11 @@
   ** the set_min_heap_reclamation_point() macro.
   */
   #define	restore_hp(src)	(					\
-  			LVALUE_CAST(Word,MR_hp) = (src),		\
-  			(void)0						\
-  		)
-
-  /*
-  #define	restore_hp(src)	(					\
   			LVALUE_CAST(Word,MR_hp) =			\
   			  ( (Word) MR_min_hp_rec < (src) ?		\
   			  (src) : (Word) MR_min_hp_rec ),		\
   			(void)0						\
   		)
-  */
   
   #define hp_alloc(count)  incr_hp(hp,count)
   #define hp_alloc_atomic(count) incr_hp_atomic(count)
diff -u -r bak/mercury/runtime/mercury_misc.h mercury/runtime/mercury_misc.h
--- bak/mercury/runtime/mercury_misc.h	Fri May 22 10:01:38 1998
+++ mercury/runtime/mercury_misc.h	Wed Jun  3 13:34:02 1998
@@ -79,6 +79,9 @@
 ** standard memcpy and generates inline code for them. Unfortunately this
 ** causes it to abort because it tries to use a register that we're already
 ** reserved.
+** XXX Eventually we should include -fno-builtin in grades where we use
+** machine registers, since pragma c_code might contain calls to memcpy,
+** strcpy, and the other functions that gcc specializes.
 */
 void MR_memcpy(char *dest, const char *src, size_t nbytes);
 
diff -u -r bak/mercury/runtime/mercury_thread.c mercury/runtime/mercury_thread.c
--- bak/mercury/runtime/mercury_thread.c	Fri May 22 10:01:30 1998
+++ mercury/runtime/mercury_thread.c	Wed Jun  3 15:06:48 1998
@@ -23,12 +23,12 @@
 
 bool	MR_exit_now;
 
-void *init_thread(void *unused);
+void *init_pthread(void *when_to_use);
 
 Declare_entry(do_runnext);
 
 #ifdef MR_THREAD_SAFE
-MercuryThread *create_thread(int x)
+MercuryThread *create_thread(void)
 {
 	MercuryThread *thread;
 	pthread_attr_t attrs;
@@ -36,7 +36,7 @@
 
 	thread = make(MercuryThread);
 	pthread_attr_init(&attrs);
-	err = pthread_create(thread, &attrs, init_thread, (void *) x);
+	err = pthread_create(thread, &attrs, init_pthread, NULL);
 
 #if 0
 	fprintf(stderr, "pthread_create returned %d (errno = %d)\n",
@@ -48,9 +48,18 @@
 
 	return thread;
 }
+
+void *init_pthread(void *unsed)
+{
+	init_thread(MR_use_later);
+
+	return NULL;
+}
+
 #endif
 
-void *init_thread(void *unused)
+
+void init_thread(MR_when_to_use when_to_use)
 {
 	MercuryEngine *eng;
 
@@ -69,7 +78,8 @@
 
 	save_registers();
 #else
-	MR_memcpy(&MR_engine_base, eng, sizeof(MercuryEngine));
+	MR_memcpy((void *) &MR_engine_base, (const void *) eng,
+		sizeof(MercuryEngine));
 	restore_registers();
 
 	load_engine_regs(MR_engine_base);
@@ -82,13 +92,19 @@
 	MR_ENGINE(owner_thread) = pthread_self();
 #endif
 
-	if (unused == 0) {
-		call_engine(ENTRY(do_runnext));
-
-		destroy_engine(eng);
+	switch (when_to_use) {
+		case (int) MR_use_later :
+			call_engine(ENTRY(do_runnext));
+
+			destroy_engine(eng);
+			return;
+
+		case (int) MR_use_now :
+			return;
+		
+		default:
+			fatal_error("init_thread was passed a bad value");
 	}
-
-	return NULL;
 }
 
 #ifdef	MR_THREAD_SAFE
@@ -145,6 +161,11 @@
 	assert(err == 0);
 }
 #endif
+
+/*
+INIT mercury_scheduler_wrapper
+ENDINIT
+*/
 
 
 Define_extern_entry(do_runnext);
diff -u -r bak/mercury/runtime/mercury_thread.h mercury/runtime/mercury_thread.h
--- bak/mercury/runtime/mercury_thread.h	Fri May 22 10:01:42 1998
+++ mercury/runtime/mercury_thread.h	Wed Jun  3 15:07:01 1998
@@ -59,9 +59,9 @@
     #define	MR_KEY_CREATE		pthread_key_create
   #endif
 
-MercuryThread	*create_thread(int x);
-void		destroy_thread(void *eng);
-extern bool	MR_exit_now;
+MercuryThread		*create_thread(void);
+void			destroy_thread(void *eng);
+extern volatile bool	MR_exit_now;
 
 #else /* not MR_THREAD_SAFE */
 
@@ -73,6 +73,17 @@
 
 #endif
 
-void	*init_thread(void *);
+/*
+** The following enum is used as the argument to init_thread.
+** MR_use_now should be passed to init_thread to indicate that
+** it has been called in a context in which it should initialize
+** the current thread's environment and return.
+** MR_use_later should be passed to indicate that the thread should
+** be initialized, then suspend waiting for work to appear in the
+** runqueue.
+*/
+typedef enum { MR_use_now, MR_use_later } MR_when_to_use;
+
+void	init_thread(MR_when_to_use);
 
 #endif
diff -u -r bak/mercury/runtime/mercury_wrapper.c mercury/runtime/mercury_wrapper.c
--- bak/mercury/runtime/mercury_wrapper.c	Fri May 22 10:01:32 1998
+++ mercury/runtime/mercury_wrapper.c	Wed Jun  3 15:06:01 1998
@@ -225,15 +225,15 @@
 
 	/* start up the Mercury engine */
 #ifndef MR_THREAD_SAFE
-	init_thread((void *) 1);
+	init_thread(MR_use_now);
 #else
 	{
 		int i;
 		init_thread_stuff();
-		init_thread((void *)1);
+		init_thread(MR_use_now);
 		MR_exit_now = FALSE;
 		for (i = 1 ; i < MR_num_threads ; i++)
-			create_thread(0);
+			create_thread();
 	}
 #endif
 
@@ -717,10 +717,8 @@
 		"-zt<n> \t\tallocate n kb for the trail redzone\n"
 #endif
 		"-C<n> \t\tprimary cache size in kbytes\n"
-#ifdef PARALLEL
 		"-P<n> \t\tnumber of processes to use for parallel execution\n"
-		"\t\tapplies only if Mercury is configured with --enable-parallel\n"
-#endif
+		"\t\tapplies only in .par grades\n"
 		"-r<n> \t\trepeat n times\n"
 		"-w<name> \tcall predicate with given name (default: main/2)\n"
 		"-1<x> \t\tinitialize register r1 with value x\n"
diff -u -r bak/mercury/scripts/init_grade_options.sh-subr mercury/scripts/init_grade_options.sh-subr
--- bak/mercury/scripts/init_grade_options.sh-subr	Tue Apr 28 10:11:47 1998
+++ mercury/scripts/init_grade_options.sh-subr	Tue Apr 28 13:02:27 1998
@@ -23,7 +23,7 @@
 use_trail=false
 args_method=compact
 debug=false
-thread_safe=true
+thread_safe=false
 
 case $# in
 	0) set - "--grade $DEFAULT_GRADE" ;;
diff -u -r bak/mercury/scripts/parse_grade_options.sh-subr mercury/scripts/parse_grade_options.sh-subr
--- bak/mercury/scripts/parse_grade_options.sh-subr	Tue Apr 28 10:11:51 1998
+++ mercury/scripts/parse_grade_options.sh-subr	Wed Jun  3 14:15:48 1998
@@ -45,6 +45,9 @@
 		esac
 		;;
 
+	--parallel)
+		thread_safe=true ;;
+
 	-p|--profiling|--time-profiling)
 		profile_time=true
 		profile_calls=true



More information about the developers mailing list