diff --git a/C/cdmgr.c b/C/cdmgr.c index de4cd2797..8bf8d6ac0 100644 --- a/C/cdmgr.c +++ b/C/cdmgr.c @@ -11,8 +11,11 @@ * File: cdmgr.c * * comments: Code manager * * * -* Last rev: $Date: 2008-03-22 23:35:00 $,$Author: vsc $ * +* Last rev: $Date: 2008-03-24 23:48:47 $,$Author: vsc $ * * $Log: not supported by cvs2svn $ +* Revision 1.221 2008/03/22 23:35:00 vsc +* fix bug in all_calls +* * Revision 1.220 2008/03/17 18:31:16 vsc * fix breakage in module system * disable stack writing in error for now @@ -3354,7 +3357,7 @@ all_calls(void) } else { ts[2] = ts[3] = TermNil; } - return(Yap_MkApplTerm(f,4,ts)); + return Yap_MkApplTerm(f,4,ts); } Term diff --git a/C/errors.c b/C/errors.c index d663efa6c..080944a0e 100644 --- a/C/errors.c +++ b/C/errors.c @@ -1328,6 +1328,20 @@ Yap_Error(yap_error_number type, Term where, char *format,...) serious = TRUE; } break; + case RESOURCE_ERROR_MAX_THREADS: + { + int i; + Term ti[1]; + + i = strlen(tmpbuf); + ti[0] = MkAtomTerm(Yap_LookupAtom("max_threads")); + nt[0] = Yap_MkApplTerm(Yap_MkFunctor(Yap_LookupAtom("resource_error"),1), 1, ti); + tp = tmpbuf+i; + psize -= i; + fun = Yap_MkFunctor(Yap_LookupAtom("error"),2); + serious = TRUE; + } + break; case SYNTAX_ERROR: { int i; diff --git a/C/threads.c b/C/threads.c index c4785d78b..a995c5206 100644 --- a/C/threads.c +++ b/C/threads.c @@ -47,11 +47,13 @@ allocate_new_tid(void) (ThreadHandle[new_worker_id].in_use == TRUE || ThreadHandle[new_worker_id].zombie == TRUE) ) new_worker_id++; - pthread_mutex_lock(&(ThreadHandle[new_worker_id].tlock)); - ThreadHandle[new_worker_id].in_use = TRUE; + if (new_worker_id < MAX_WORKERS) { + pthread_mutex_lock(&(ThreadHandle[new_worker_id].tlock)); + ThreadHandle[new_worker_id].in_use = TRUE; + } else { + new_worker_id = -1; + } UNLOCK(ThreadHandlesLock); - if (new_worker_id == MAX_WORKERS) - return -1; return new_worker_id; } @@ -180,7 +182,12 @@ thread_run(void *widp) static Int p_thread_new_tid(void) { - return Yap_unify(MkIntegerTerm(allocate_new_tid()), ARG1); + int new_worker = allocate_new_tid(); + if (new_worker == -1) { + Yap_Error(RESOURCE_ERROR_MAX_THREADS, MkIntegerTerm(MAX_WORKERS), ""); + return FALSE; + } + return Yap_unify(MkIntegerTerm(new_worker), ARG1); } static void diff --git a/H/Yap.h b/H/Yap.h index 8fb19e8c9..ca2bba203 100644 --- a/H/Yap.h +++ b/H/Yap.h @@ -10,7 +10,7 @@ * File: Yap.h.m4 * * mods: * * comments: main header file for YAP * -* version: $Id: Yap.h,v 1.28 2008-03-13 18:41:50 vsc Exp $ * +* version: $Id: Yap.h,v 1.29 2008-03-24 23:48:47 vsc Exp $ * *************************************************************************/ #include "config.h" @@ -471,6 +471,7 @@ typedef enum REPRESENTATION_ERROR_CHARACTER, REPRESENTATION_ERROR_CHARACTER_CODE, REPRESENTATION_ERROR_MAX_ARITY, + RESOURCE_ERROR_MAX_THREADS, RETRY_COUNTER_UNDERFLOW, SYNTAX_ERROR, SYSTEM_ERROR, diff --git a/pl/hacks.yap b/pl/hacks.yap index a7a4940ef..461aeb9f6 100644 --- a/pl/hacks.yap +++ b/pl/hacks.yap @@ -11,7 +11,7 @@ * File: utilities for messing around in YAP internals. * * comments: error messages for YAP * * * -* Last rev: $Date: 2008-03-17 18:31:16 $,$Author: vsc $ * +* Last rev: $Date: 2008-03-24 23:48:47 $,$Author: vsc $ * * * * * *************************************************************************/ @@ -74,7 +74,10 @@ display_stack_info([],[Env|Envs],I,Cont) --> { I1 is I-1 }, display_stack_info([], Envs, I1, NCont). display_stack_info([CP|LCPs],[Env|LEnvs],I,Cont) --> - { yap_hacks:continuation(Env, _, NCont, CB), I1 is I-1 }, + { + yap_hacks:continuation(Env, _, NCont, CB), + I1 is I-1 + }, ( { CP == Env, CB < CP } -> % if we follow choice-point and we cut to before choice-point % we are the same goal diff --git a/pl/messages.yap b/pl/messages.yap index 762b6f542..d3332d26d 100644 --- a/pl/messages.yap +++ b/pl/messages.yap @@ -11,7 +11,7 @@ * File: utilities for displaying messages in YAP. * * comments: error messages for YAP * * * -* Last rev: $Date: 2008-03-17 18:31:16 $,$Author: vsc $ * +* Last rev: $Date: 2008-03-24 23:48:47 $,$Author: vsc $ * * * * * *************************************************************************/ @@ -190,7 +190,7 @@ system_message(error(permission_error(access,static_procedure,P), Where)) --> [ 'PERMISSION ERROR- ~w: cannot access static procedure ~w' - [Where,P] ]. system_message(error(permission_error(alias,new,P), Where)) --> [ 'PERMISSION ERROR- ~w: cannot create alias ~w' - [Where,P] ]. -system_message(error(permission_error(create,array,P), Where)) --> +system_message(error(permission_error(create,Name,P), Where)) --> { object_name(Name, ObjName) }, [ 'PERMISSION ERROR- ~w: cannot create ~a ~w' - [Where,ObjName,P] ]. system_message(error(permission_error(input,binary_stream,Stream), Where)) --> @@ -237,6 +237,8 @@ system_message(error(representation_error(character_code), Where)) --> [ 'REPRESENTATION ERROR- ~w: expected character code' - [Where] ]. system_message(error(representation_error(max_arity), Where)) --> [ 'REPRESENTATION ERROR- ~w: number too big' - [Where] ]. +system_message(error(resource_error(max_threads), Where)) --> + [ 'RESOURCE ERROR- too many open threads' - [Where] ]. system_message(error(syntax_error(G,0,Msg,[],0,0), _)) --> [ 'SYNTAX ERROR: ~a' - [G,Msg] ]. system_message(error(syntax_error(_,_,_,Term,Pos,Start), Where)) -->