From: Terrance S. <ts...@us...> - 2007-06-26 17:00:07
|
Update of /cvsroot/xsb/XSB/emu In directory sc8-pr-cvs10.sourceforge.net:/tmp/cvs-serv29976 Modified Files: flag_defs_xsb.h init_xsb.c thread_defs_xsb.h thread_xsb.c Log Message: Now allowing modifications of default values for thread create via xsb_flag. Altered thread create so that values can either be explicitly passed in, or obtained from flags. Also, added usleep() as a temporary fix to a problem that I'll send out a note about. Index: flag_defs_xsb.h =================================================================== RCS file: /cvsroot/xsb/XSB/emu/flag_defs_xsb.h,v retrieving revision 1.20 retrieving revision 1.21 diff -u -r1.20 -r1.21 --- flag_defs_xsb.h 1 Jun 2007 22:47:06 -0000 1.20 +++ flag_defs_xsb.h 26 Jun 2007 16:59:58 -0000 1.21 @@ -118,8 +118,13 @@ #define STRING_GARBAGE_COLLECT 70 /* Turn string gc on or off */ #define TABLE_GC_ACTION 71 /* Action for recl. of tables with cond answers */ +#define THREAD_GLSIZE 72 /* Initial GLSize for created thread */ +#define THREAD_TCPSIZE 73 /* Initial TCSize for created thread */ +#define THREAD_COMPLSIZE 74 /* Initial COMPLSize for created thread */ +#define THREAD_PDLSIZE 75 /* Initial PDLSize for created thread */ +#define THREAD_DETACHED 76 /* Initial Detached flag for created thread */ -#define MAX_FLAGS 75 +#define MAX_FLAGS 80 #define MAXTOINDEX 5 /* depth in term to go when using deep indexing */ Index: init_xsb.c =================================================================== RCS file: /cvsroot/xsb/XSB/emu/init_xsb.c,v retrieving revision 1.123 retrieving revision 1.124 diff -u -r1.123 -r1.124 --- init_xsb.c 10 Jun 2007 18:43:58 -0000 1.123 +++ init_xsb.c 26 Jun 2007 16:59:59 -0000 1.124 @@ -113,16 +113,6 @@ TCPSTACK_DEFAULT_SIZE}, /* Trail + CP Stack */ complstack = {NULL, NULL, 0, COMPLSTACK_DEFAULT_SIZE}; /* Completion Stack */ -#else -static System_Stack -init_pdl = {NULL, NULL, 0, - PDL_DEFAULT_SIZE}, /* PDL */ - init_glstack = {NULL, NULL, 0, - GLSTACK_DEFAULT_SIZE}, /* Global + Local Stacks */ - init_tcpstack = {NULL, NULL, 0, - TCPSTACK_DEFAULT_SIZE}, /* Trail + CP Stack */ - init_complstack = {NULL, NULL, 0, - COMPLSTACK_DEFAULT_SIZE}; /* Completion Stack */ #endif Exec_Mode xsb_mode; /* How XSB is run: interp, disassem, user spec, etc. */ @@ -224,6 +214,11 @@ pflags[BACKTRACE] = 1; /* Backtrace on error by default */ pflags[CLAUSE_GARBAGE_COLLECT] = 1; /* Clause GC on by default */ flags[STRING_GARBAGE_COLLECT] = 1; /* String GC on by default */ + + flags[THREAD_PDLSIZE] = PDL_DEFAULT_SIZE; + flags[THREAD_GLSIZE] = GLSTACK_DEFAULT_SIZE; + flags[THREAD_TCPSIZE] = TCPSTACK_DEFAULT_SIZE; + flags[THREAD_COMPLSIZE] = COMPLSTACK_DEFAULT_SIZE; } /*==========================================================================*/ @@ -356,7 +351,7 @@ } /*==========================================================================*/ -/* Currently done on process startup after init_para(). Do not use elsewhere, +/* Currently done on process startup before init_para(). Do not use elsewhere, to avoid problems with multi-threading. */ FILE *stream_err, *stream_out; @@ -366,7 +361,6 @@ int i; init_flags(CTXT); // We set one of them - /* This needs to be done early so that embedded applications can catch meaningful initialization failures in the log files @@ -530,7 +524,7 @@ #ifndef MULTI_THREAD sscanf(argv[i]+2, "%ld", &pdl.init_size); #else - sscanf(argv[i]+2, "%ld", &init_pdl.init_size); + sscanf(argv[i]+2, "%ld", &flags[THREAD_PDLSIZE]); #endif else { i++; @@ -538,7 +532,7 @@ #ifndef MULTI_THREAD sscanf(argv[i], "%ld", &pdl.init_size); #else - sscanf(argv[i], "%ld", &init_pdl.init_size); + sscanf(argv[i], "%ld", &flags[THREAD_PDLSIZE]); #endif else xsb_warn("Missing size value for -u"); @@ -549,7 +543,7 @@ #ifndef MULTI_THREAD sscanf(argv[i]+2, "%ld", &glstack.init_size); #else - sscanf(argv[i]+2, "%ld", &init_glstack.init_size); + sscanf(argv[i]+2, "%ld", &flags[THREAD_GLSIZE]); #endif else { i++; @@ -557,7 +551,8 @@ #ifndef MULTI_THREAD sscanf(argv[i], "%ld", &glstack.init_size); #else - sscanf(argv[i], "%ld", &init_glstack.init_size); + sscanf(argv[i], "%ld", &flags[THREAD_GLSIZE]); + #endif else xsb_warn("Missing size value for -m"); @@ -568,7 +563,7 @@ #ifndef MULTI_THREAD sscanf(argv[i]+2, "%ld", &tcpstack.init_size); #else - sscanf(argv[i]+2, "%ld", &init_tcpstack.init_size); + sscanf(argv[i]+2, "%ld", &flags[THREAD_TCPSIZE]); #endif else { i++; @@ -576,7 +571,7 @@ #ifndef MULTI_THREAD sscanf(argv[i], "%ld", &tcpstack.init_size); #else - sscanf(argv[i], "%ld", &init_tcpstack.init_size); + sscanf(argv[i], "%ld", &flags[THREAD_TCPSIZE]); #endif else xsb_warn("Missing size value for -c"); @@ -587,7 +582,7 @@ #ifndef MULTI_THREAD sscanf(argv[i]+2, "%ld", &complstack.init_size); #else - sscanf(argv[i]+2, "%ld", &init_complstack.init_size); + sscanf(argv[i]+2, "%ld", &flags[THREAD_COMPLSIZE]); #endif else { i++; @@ -595,7 +590,7 @@ #ifndef MULTI_THREAD sscanf(argv[i], "%ld", &complstack.init_size); #else - sscanf(argv[i], "%ld", &init_complstack.init_size); + sscanf(argv[i], "%ld", &flags[THREAD_COMPLSIZE]); #endif else xsb_warn("Missing size value for -o"); @@ -834,33 +829,10 @@ /*==========================================================================*/ #ifdef MULTI_THREAD -void set_init_glstack_size(int s) -{ - init_glstack.size = s ; -} - -void set_init_tcpstack_size(int s) -{ - init_tcpstack.size = s ; -} - -void set_init_pdl_size(int s) -{ - init_pdl.size = s ; -} - -void set_init_complstack_size(int s) -{ - init_complstack.size = s ; -} - - - /* To be called each time a thread is created: initializes * thread-private memory areas that are cleaned up in * cleanup_thread_structures() */ - void init_thread_structures(CTXTdecl) { @@ -869,10 +841,10 @@ asynint_code = 0; asynint_val = 0; - pdl = init_pdl ; - glstack = init_glstack ; - tcpstack = init_tcpstack ; - complstack = init_complstack ; + pdl.low = NULL; pdl.high = NULL; pdl.size = 0, pdl.init_size = (long) flags[THREAD_PDLSIZE]; + tcpstack.low = NULL; tcpstack.high = NULL; tcpstack.size = 0, tcpstack.init_size = (long) flags[THREAD_TCPSIZE]; + glstack.low = NULL; glstack.high = NULL; glstack.size = 0, glstack.init_size = (long) flags[THREAD_GLSIZE]; + complstack.low = NULL; complstack.high = NULL; complstack.size = 0, complstack.init_size = (long) flags[THREAD_COMPLSIZE]; findall_solutions = NULL; Index: thread_defs_xsb.h =================================================================== RCS file: /cvsroot/xsb/XSB/emu/thread_defs_xsb.h,v retrieving revision 1.29 retrieving revision 1.30 diff -u -r1.29 -r1.30 --- thread_defs_xsb.h 24 Apr 2007 18:35:31 -0000 1.29 +++ thread_defs_xsb.h 26 Jun 2007 16:59:59 -0000 1.30 @@ -28,7 +28,7 @@ /* THREAD PRIMITIVES */ -#define XSB_THREAD_CREATE 1 +#define XSB_THREAD_CREATE_FLAGS 1 #define XSB_THREAD_EXIT 2 #define XSB_THREAD_JOIN 3 #define XSB_THREAD_DETACH 4 @@ -79,6 +79,8 @@ #define PRINT_MESSAGE_QUEUE 40 +#define XSB_THREAD_CREATE_PARAMS 41 + #define MAX_THREADS 1024 Index: thread_xsb.c =================================================================== RCS file: /cvsroot/xsb/XSB/emu/thread_xsb.c,v retrieving revision 1.78 retrieving revision 1.79 diff -u -r1.78 -r1.79 --- thread_xsb.c 26 Jun 2007 14:03:59 -0000 1.78 +++ thread_xsb.c 26 Jun 2007 16:59:59 -0000 1.79 @@ -71,10 +71,6 @@ int emuloop(CTXTdeclc byte *startaddr); void cleanup_thread_structures(CTXTdecl); void init_machine(CTXTdeclc int, int, int, int); -void set_init_glstack_size(int); -void set_init_tcpstack_size(int); -void set_init_pdl_size(int); -void set_init_complstack_size(int); Cell copy_term_from_thread( th_context *th, th_context *from, Cell arg1 ); int copy_term_to_message_queue(th_context *th, Cell arg1); @@ -377,9 +373,9 @@ /*-------------------*/ -static int xsb_thread_create(th_context *th) -{ - int rc, is_detached,is_aliased ; +static int xsb_thread_create(th_context *th, int glsize, int tcsize, int complsize,int pdlsize, + int is_detached, int is_aliased) { + int rc; Cell goal ; th_context *new_th_ctxt ; pthread_t *thr ; @@ -389,9 +385,6 @@ // goal = ptoc_tag(th, 2) ; iso_check_var(th, 3,"thread_create/[2,3]"); // should check here, rather than at end - is_detached = ptoc_int(CTXTc 8); - is_aliased = ptoc_int(CTXTc 8); - new_th_ctxt = mem_alloc(sizeof(th_context),THREAD_SPACE) ; pthread_mutex_lock( &th_mutex ); @@ -399,6 +392,7 @@ id = pos = th_new( new_th_ctxt, is_detached, is_aliased ); if (pos < 0) { pthread_mutex_unlock( &th_mutex ); + mem_dealloc(new_th_ctxt,sizeof(th_context),THREAD_SPACE); xsb_resource_error(CTXTc "maximum threads","thread_create",3); } flags[NUM_THREADS]++ ; @@ -406,13 +400,13 @@ pthread_mutex_unlock( &th_mutex ); copy_pflags(new_th_ctxt, th) ; - init_machine(new_th_ctxt,ptoc_int(CTXTc 4),ptoc_int(CTXTc 5), - ptoc_int(CTXTc 6),ptoc_int(CTXTc 7)) ; + init_machine(new_th_ctxt,glsize,tcsize,complsize,pdlsize); new_th_ctxt->_reg[1] = copy_term_from_thread(new_th_ctxt, th, goal) ; SET_THREAD_INCARN(id, th_vec[pos].incarn ) ; new_th_ctxt->tid = id ; thr = &th_vec[pos].tid ; + if (is_detached) { /* set detached */ rc = pthread_create(thr, &detached_attr_gl, &xsb_thread_run, (void *)new_th_ctxt ) ; @@ -420,8 +414,9 @@ else { rc = pthread_create(thr, &normal_attr_gl, &xsb_thread_run, (void *)new_th_ctxt ) ; } - th_vec[pos].valid = TRUE ; + // printf("creating %p %p\n",thr,th_vec[pos].tid); + usleep(100); if (rc == EAGAIN) { xsb_resource_error(th,"system threads","xsb_thread_create",2); } else { @@ -718,8 +713,16 @@ switch( request_num ) { - case XSB_THREAD_CREATE: - rc = xsb_thread_create(th) ; + /* Flags use default values, params have explicit + parameters sent in */ + case XSB_THREAD_CREATE_FLAGS: + rc = xsb_thread_create(th,flags[THREAD_GLSIZE],flags[THREAD_TCPSIZE],flags[THREAD_COMPLSIZE], + flags[THREAD_PDLSIZE],flags[THREAD_DETACHED],0) ; + break ; + + case XSB_THREAD_CREATE_PARAMS: + rc = xsb_thread_create(th,ptoc_int(CTXTc 4),ptoc_int(CTXTc 5), + ptoc_int(CTXTc 6),ptoc_int(CTXTc 7), ptoc_int(CTXTc 8), ptoc_int(CTXTc 9)); break ; /* TLS: replaced thread_free_tab_blks() by @@ -729,6 +732,7 @@ structure managers directly. */ case XSB_THREAD_EXIT: + // printf("exiting %p\n",pthread_self()); rval = ptoc_int(CTXTc 2 ) ; release_held_mutexes(CTXT); release_private_tabling_resources(CTXT); @@ -946,35 +950,6 @@ rc = 0; break; - case XSB_SET_INIT_GLSTACK_SIZE: - i = ptoc_int(CTXTc 2) ; - if( !VALID_THREAD(i) ) - xsb_abort( "[THREAD] Invalid Thread Id" ) ; - set_init_glstack_size(i); - rc = 0; - break; - case XSB_SET_INIT_TCPSTACK_SIZE: - i = ptoc_int(CTXTc 2) ; - if( !VALID_THREAD(i) ) - xsb_abort( "[THREAD] Invalid Thread Id" ) ; - set_init_tcpstack_size(i); - rc = 0; - break; - case XSB_SET_INIT_PDL_SIZE: - i = ptoc_int(CTXTc 2) ; - if( !VALID_THREAD(i) ) - xsb_abort( "[THREAD] Invalid Thread Id" ) ; - set_init_pdl_size(i); - rc = 0; - break; - case XSB_SET_INIT_COMPLSTACK_SIZE: - i = ptoc_int(CTXTc 2) ; - if( !VALID_THREAD(i) ) - xsb_abort( "[THREAD] Invalid Thread Id" ) ; - set_init_complstack_size(i); - rc = 0; - break; - /* TLS: may generalize -- right now, just detached/joinable */ case XSB_THREAD_PROPERTY: i = ptoc_int(CTXTc 2); |