fix maximum number of threads open error

git-svn-id: https://yap.svn.sf.net/svnroot/yap/trunk@2158 b08c6af1-5177-4d33-ba66-4b1c6b8b522a
This commit is contained in:
vsc 2008-03-24 23:48:47 +00:00
parent ba2023436a
commit c20c0f7767
6 changed files with 42 additions and 12 deletions

View File

@ -11,8 +11,11 @@
* File: cdmgr.c * * File: cdmgr.c *
* comments: Code manager * * 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 $ * $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 * Revision 1.220 2008/03/17 18:31:16 vsc
* fix breakage in module system * fix breakage in module system
* disable stack writing in error for now * disable stack writing in error for now
@ -3354,7 +3357,7 @@ all_calls(void)
} else { } else {
ts[2] = ts[3] = TermNil; ts[2] = ts[3] = TermNil;
} }
return(Yap_MkApplTerm(f,4,ts)); return Yap_MkApplTerm(f,4,ts);
} }
Term Term

View File

@ -1328,6 +1328,20 @@ Yap_Error(yap_error_number type, Term where, char *format,...)
serious = TRUE; serious = TRUE;
} }
break; 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: case SYNTAX_ERROR:
{ {
int i; int i;

View File

@ -47,11 +47,13 @@ allocate_new_tid(void)
(ThreadHandle[new_worker_id].in_use == TRUE || (ThreadHandle[new_worker_id].in_use == TRUE ||
ThreadHandle[new_worker_id].zombie == TRUE) ) ThreadHandle[new_worker_id].zombie == TRUE) )
new_worker_id++; new_worker_id++;
if (new_worker_id < MAX_WORKERS) {
pthread_mutex_lock(&(ThreadHandle[new_worker_id].tlock)); pthread_mutex_lock(&(ThreadHandle[new_worker_id].tlock));
ThreadHandle[new_worker_id].in_use = TRUE; ThreadHandle[new_worker_id].in_use = TRUE;
} else {
new_worker_id = -1;
}
UNLOCK(ThreadHandlesLock); UNLOCK(ThreadHandlesLock);
if (new_worker_id == MAX_WORKERS)
return -1;
return new_worker_id; return new_worker_id;
} }
@ -180,7 +182,12 @@ thread_run(void *widp)
static Int static Int
p_thread_new_tid(void) 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 static void

View File

@ -10,7 +10,7 @@
* File: Yap.h.m4 * * File: Yap.h.m4 *
* mods: * * mods: *
* comments: main header file for YAP * * 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" #include "config.h"
@ -471,6 +471,7 @@ typedef enum
REPRESENTATION_ERROR_CHARACTER, REPRESENTATION_ERROR_CHARACTER,
REPRESENTATION_ERROR_CHARACTER_CODE, REPRESENTATION_ERROR_CHARACTER_CODE,
REPRESENTATION_ERROR_MAX_ARITY, REPRESENTATION_ERROR_MAX_ARITY,
RESOURCE_ERROR_MAX_THREADS,
RETRY_COUNTER_UNDERFLOW, RETRY_COUNTER_UNDERFLOW,
SYNTAX_ERROR, SYNTAX_ERROR,
SYSTEM_ERROR, SYSTEM_ERROR,

View File

@ -11,7 +11,7 @@
* File: utilities for messing around in YAP internals. * * File: utilities for messing around in YAP internals. *
* comments: error messages for 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 $ *
* * * *
* * * *
*************************************************************************/ *************************************************************************/
@ -74,7 +74,10 @@ display_stack_info([],[Env|Envs],I,Cont) -->
{ I1 is I-1 }, { I1 is I-1 },
display_stack_info([], Envs, I1, NCont). display_stack_info([], Envs, I1, NCont).
display_stack_info([CP|LCPs],[Env|LEnvs],I,Cont) --> 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 } -> ( { CP == Env, CB < CP } ->
% if we follow choice-point and we cut to before choice-point % if we follow choice-point and we cut to before choice-point
% we are the same goal % we are the same goal

View File

@ -11,7 +11,7 @@
* File: utilities for displaying messages in YAP. * * File: utilities for displaying messages in YAP. *
* comments: error messages for 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] ]. [ 'PERMISSION ERROR- ~w: cannot access static procedure ~w' - [Where,P] ].
system_message(error(permission_error(alias,new,P), Where)) --> system_message(error(permission_error(alias,new,P), Where)) -->
[ 'PERMISSION ERROR- ~w: cannot create alias ~w' - [Where,P] ]. [ '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) }, { object_name(Name, ObjName) },
[ 'PERMISSION ERROR- ~w: cannot create ~a ~w' - [Where,ObjName,P] ]. [ 'PERMISSION ERROR- ~w: cannot create ~a ~w' - [Where,ObjName,P] ].
system_message(error(permission_error(input,binary_stream,Stream), Where)) --> 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] ]. [ 'REPRESENTATION ERROR- ~w: expected character code' - [Where] ].
system_message(error(representation_error(max_arity), Where)) --> system_message(error(representation_error(max_arity), Where)) -->
[ 'REPRESENTATION ERROR- ~w: number too big' - [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), _)) --> system_message(error(syntax_error(G,0,Msg,[],0,0), _)) -->
[ 'SYNTAX ERROR: ~a' - [G,Msg] ]. [ 'SYNTAX ERROR: ~a' - [G,Msg] ].
system_message(error(syntax_error(_,_,_,Term,Pos,Start), Where)) --> system_message(error(syntax_error(_,_,_,Term,Pos,Start), Where)) -->