diff --git a/C/eval.c b/C/eval.c index 1f4caf178..74cc498b8 100644 --- a/C/eval.c +++ b/C/eval.c @@ -108,6 +108,12 @@ Eval(Term t, E_ARGS) } } } else if (IsPairTerm(t)) { + if (TailOfTerm(t) != TermNil) { + Yap_Error(TYPE_ERROR_EVALUABLE, t, + "string must contain a single character to be evaluated as an arithmetic expression"); + P = (yamop *)FAILCODE; + RERROR(); + } return(Eval(HeadOfTerm(t), USE_E_ARGS)); } else if (IsIntTerm(t)) { RINT(IntOfTerm(t)); @@ -182,6 +188,12 @@ Yap_Eval(Term t, E_ARGS) } } } else if (IsPairTerm(t)) { + if (TailOfTerm(t) != TermNil) { + Yap_Error(TYPE_ERROR_EVALUABLE, t, + "string must contain a single character to be evaluated as an arithmetic expression"); + P = (yamop *)FAILCODE; + RERROR(); + } return(Eval(HeadOfTerm(t), USE_E_ARGS)); } else if (IsIntTerm(t)) { RINT(IntOfTerm(t)); diff --git a/C/threads.c b/C/threads.c index 6cfb94698..d27f98ff7 100644 --- a/C/threads.c +++ b/C/threads.c @@ -101,7 +101,6 @@ kill_thread_engine (int wid) Yap_KillStacks(wid); Yap_FreeCodeSpace((ADDR)(ThreadHandle[wid].tgoal)); Yap_heap_regs->wl[wid].active_signals = 0L; - pthread_mutex_lock(&(ThreadHandle[wid].tlock)); free(Yap_heap_regs->wl[wid].scratchpad.ptr); free(ThreadHandle[wid].default_yaam_regs); ThreadHandle[wid].current_yaam_regs = NULL; @@ -356,7 +355,6 @@ Yap_thread_detach_engine(int wid) Int Yap_thread_destroy_engine(int wid) { - pthread_mutex_lock(&(ThreadHandle[wid].tlock)); if (ThreadHandle[wid].ref_count == 0) { kill_thread_engine(wid); return TRUE; @@ -382,6 +380,7 @@ p_thread_join(void) UNLOCK(ThreadHandlesLock); return FALSE; } + pthread_mutex_lock(&(ThreadHandle[tid].tlock)); UNLOCK(ThreadHandlesLock); /* make sure this lock is accessible */ if (pthread_join(ThreadHandle[tid].handle, NULL) < 0) { @@ -413,7 +412,6 @@ p_thread_detach(void) } ThreadHandle[tid].tdetach = MkAtomTerm(AtomTrue); - pthread_mutex_unlock(&(ThreadHandle[tid].tlock)); return TRUE; } @@ -670,9 +668,10 @@ p_thread_runtime(void) } static Int -p_thread_self_lock(void) +p_thread_unlock(void) { /* '$thread_self_lock' */ - pthread_mutex_lock(&(ThreadHandle[worker_id].tlock)); + Int wid = IntegerOfTerm(Deref(ARG1)); + pthread_mutex_unlock(&(ThreadHandle[wid].tlock)); return TRUE; } @@ -708,6 +707,7 @@ void Yap_InitThreadPreds(void) Yap_InitCPred("$nof_threads_created", 1, p_nof_threads_created, SafePredFlag|HiddenPredFlag); Yap_InitCPred("$thread_sleep", 4, p_thread_sleep, SafePredFlag|HiddenPredFlag); Yap_InitCPred("$thread_runtime", 1, p_thread_runtime, SafePredFlag|HiddenPredFlag); + Yap_InitCPred("$thread_unlock", 1, p_thread_unlock, SafePredFlag); } #else @@ -749,7 +749,7 @@ p_thread_self(void) } static Int -p_thread_self_lock(void) +p_thread_unlock(void) { /* '$thread_runtime'(+P) */ return TRUE; } @@ -762,7 +762,7 @@ void Yap_InitThreadPreds(void) Yap_InitCPred("$nof_threads", 1, p_nof_threads, SafePredFlag|HiddenPredFlag); Yap_InitCPred("$nof_threads_created", 1, p_nof_threads_created, SafePredFlag|HiddenPredFlag); Yap_InitCPred("$thread_runtime", 1, p_thread_runtime, SafePredFlag|HiddenPredFlag); - Yap_InitCPred("$self_thread_lock", 0, p_thread_self_lock, SafePredFlag); + Yap_InitCPred("$thread_unlock", 1, p_thread_unlock, SafePredFlag); } diff --git a/docs/yap.tex b/docs/yap.tex index 054eed82e..d25f39499 100644 --- a/docs/yap.tex +++ b/docs/yap.tex @@ -3445,7 +3445,8 @@ the call. @var{Char} is a lower-case letter. @item lower(Upper) - @var{Char} is a lower-case version of Upper. Only true if @var{Char} is lowercase and Upper uppercase. + @var{Char} is a lower-case version of @var{Upper}. Only true if + @var{Char} is lowercase and @var{Upper} uppercase. @item to_lower(Upper) @var{Char} is a lower-case version of Upper. For non-letters, or letter without case, @var{Char} and Lower are the same. See also upcase_atom/2 and downcase_atom/2. diff --git a/pl/threads.yap b/pl/threads.yap index c9a3c9726..64917c737 100644 --- a/pl/threads.yap +++ b/pl/threads.yap @@ -337,7 +337,8 @@ thread_detach(Id) :- ( recorded('$thread_exit_status', [Id0|_], _) -> '$erase_thread_info'(Id0), '$thread_destroy'(Id0) - ; true + ; + '$thread_unlock'(Id0) ). thread_exit(Term) :- @@ -637,6 +638,7 @@ message_queue_destroy(Queue) :- recorded('$queue',q(Queue,Mutex,Cond,_,QKey),R), !, erase(R), '$cond_destroy'(Cond), + write(Queue:Mutex),nl, '$destroy_mutex'(Mutex), '$unlock_mutex'(QMutex), '$clean_mqueue'(QKey).