The problem is that your code was wrong. It passed wrong arguments to a
function and thus it triggered an infinite chain of SIGSEGV. The right code
would be the attached one.

Note that cl_safe_eval() does not invoke the debugger and all forms that
fail are simply ignored. Thus, no thread using such code for evaluation
would lead to instabilities, were it not for other code that you write
outside that form and which is definitely wrong.

Juanjo


On Sat, Nov 3, 2012 at 12:38 AM, Peter Enerccio <enerc...@gmail.com> wrote:

> Here is my simple REPL like code. It is evaluated by this function:
>
> void eval_in_new_thread_mt(char* buffer){
>     cl_object cl_buffer = c_string_to_object(buffer);
>     thread_t* thread = create_thread(eval_nt, cl_buffer);
>     cl_object ret = (cl_object) thread_join(thread);
>     printf(": ");
>     cl_print(1, ret);
>     printf("\n\n");
> }
>
> Now, everything works fine, as long as there is no problem. But when
> problem, such as when evaluating (+ 1 'a), it will crash with sigsegv:
>
> Debugger received error of type: SIMPLE-ERROR
> Attempted to recursively lock #<lock (nonrecursive) "Console lock"> which
> is already owned by #<process 0000000002f3a000>
> Error flushed.
>
> which repeats a lot.
>
>
> 2012/11/2 Juan Jose Garcia-Ripoll <juanjose.garciarip...@gmail.com>
>
>> I am fwd this to the mailing list because I do not want to repeat these
>> answers or restart this discussion for every user that might find such
>> problems. This is what the mailing list archives are fore
>>
>> On Fri, Nov 2, 2012 at 3:46 PM, Peter Enerccio <enerc...@gmail.com>wrote:
>>
>>> Well, I can get my own stdin thread in it, but it has the problem that
>>> once there is error, it will go crazy about console resource being already
>>> acquired, all over.
>>>
>>
>> I think you are mixing things and I do not manage to make myself
>> understood. When ECL is embedded it does not launch a toplevel and there is
>> no thread that grabs the console from start. What you will see is
>>
>> * Your own threads
>> * A secondary thread that waits for signal. This thread can be
>> deactivated using ecl_set_option()
>> http://ecls.sourceforge.net/new-manual/re93.html
>>
>> Console is and should be at this point free for any thread to use. No
>> thread will be using stdin at this point and I do not understand why you
>> mention this about resource being acquired.
>>
>> Continuing with the explanation, whenever an error happens, Common Lisp
>> mandates that a default error handler exists. By default this handler will
>> invoke the debugger and it is those debuggers which will grab the console.
>> You can prevent this from happening using standard tools, which range from
>> intercepting the debugger, to setting your own handlers. But in theory, if
>> errors only happen in one thread it should be ok. Even nested errors are ok
>> if they do not totally prevent the debugger from running (i.e. stack
>> overflows may do so, memory exhaustion is a hardly correctable error)
>>
>> You say that that thread is grabbing the console and this can only be
>> happening because your program is generating interrupts, such as Ctrl-C or
>> SIGSEGV, or some other events. In this case the secondary thread spawns an
>> error handler for each signal, which is standard practice. You may
>>
>> * Change the signal handler
>> * Block the associated signals
>> * Deactivate the thread entirely but this will cause trouble.
>>
>> A more troublesome situation is when there are multiple signals coming
>> from all threads and they saturate the debugger, but hey, here there is
>> _nothing_ sensible that the implementation can do.
>>
>> So, summing up, if there is no debugger already running because some
>> thread was there, your application should be ok with having the current
>> distribution of threads. Otherwise I must ask you to provide a minimally
>> reproducible test case to solve your problems. Without a more precise
>> description I cannot do anything -- you already saw that with the outdated
>> ECL stuff.
>>
>> Juanjo
>>
>> --
>> Instituto de Física Fundamental, CSIC
>> c/ Serrano, 113b, Madrid 28006 (Spain)
>> http://juanjose.garciaripoll.googlepages.com
>>
>
>
>
> --
> Bc. Peter Vaňušanik
> http://www.bishojo.tk
>
>


-- 
Instituto de Física Fundamental, CSIC
c/ Serrano, 113b, Madrid 28006 (Spain)
http://juanjose.garciaripoll.googlepages.com

Attachment: Makefile
Description: Binary data

#include <ecl/ecl.h>
#include <gc.h>
#include <pthread.h>

void* thread_test(void* blah){
    ecl_import_current_thread(Cnil, Cnil);
    printf("\nStarting my repl:\n");

    /* This sets an outermost block for (ext:quit) */
    ECL_CATCH_ALL_BEGIN(ecl_process_env()) {
	cl_object error_value = ecl_list1(ECL_NIL);
	cl_object eof_value = ecl_list1(ECL_NIL);
	while (1) {
	    /* Read a form. Returns eof_value when EOF. Note that we
	     * have to be careful with forms that are not protected
	     * because the debugger might not be invoked. */
	    cl_object cl_buffer = cl_read(3, ECL_T, ECL_NIL, eof_value);
	    if (cl_buffer == eof_value)
		break;
	    /* The following statement is wrong */
	    /*cl_object ret = cl_safe_eval(cl_buffer, Cnil, ecl_process_env());*/
	    cl_object ret = cl_safe_eval(cl_buffer, ECL_NIL, error_value);
	    printf(": ");
	    if (ret == error_value) {
		printf("ERROR\n");
	    } else {
		cl_print(1, ret);
		printf("\n\n");
	    }
	}
    } ECL_CATCH_ALL_END;

    printf("\nExtiting repl\n");
    ecl_release_current_thread();
    return NULL;
}

int main(int argc, char** argv){

    cl_boot(argc, argv);

    pthread_t thread;
    pthread_create(&thread, NULL, thread_test, NULL);
    void* ret;
    pthread_join(thread, &ret);


    cl_shutdown();

    return 0;
}
------------------------------------------------------------------------------
Everyone hates slow websites. So do we.
Make your web apps faster with AppDynamics
Download AppDynamics Lite for free today:
http://p.sf.net/sfu/appdyn_d2d_nov
_______________________________________________
Ecls-list mailing list
Ecls-list@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/ecls-list

Reply via email to