guile-user
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

scm_shell in C-Thread - Quit vs. Terminal Corruption


From: vimml
Subject: scm_shell in C-Thread - Quit vs. Terminal Corruption
Date: Fri, 16 Oct 2009 21:09:25 +0200
User-agent: Mutt/1.5.20 (2009-06-14)

Hi Schemers!

I'm rather new to using guile, so please pardon if my question is more
trivial than I think it is :)

I have a graphics application (OpenGL) that spawns a thread which
executes scm_shell(). This way I can use the terminal to query various
information about the rendering. The program is usually exited by
pressing <ESC> in the graphics window.

I found that I am unable to cleanly terminate both threads (acutal
application and guile). When I enter 
        (quit)
in the terminal scm_shell calls exit(), which does not care much for my
application cleanup. When I press <ESC> the guile thread get aborted
when the application terminates.

To couple the guile-thread with the termination of my program I came up
with starting a new thread in my scheme initialization which checks if
the scheme-side should terminate. The pattern is shown in the following
code, typed into the guile interpreter:

guile> (define other-thread-wants-to-quit #f)
guile> (define (my-thread) (if other-thread-wants-to-quit (begin (display 
"going home")(newline)(quit))) (sleep 1) (my-thread))
guile> (call-with-new-thread my-thread)
guile> (set! other-thread-wants-to-quit #t)
guile> going home

When I run this it terminates the guile session, but also destroys my
terminal. After guile returned the prompt is visible, but the characters
thereafter are black on black, and hitting return does not break the
current line. Hm, hard to describe, look at this:
Hitting return three times yields:
shellprompt ~ $ shellprompt ~ $ shellprompt ~ $

To summarize, my questions are:
- Is there a better way to tell the scheme-thread to terminate?
- Why does the code given above mess with my terminal?
- What can I do to avoid it?

Thanks in advace, and have a nice weekend :)
        Kai





reply via email to

[Prev in Thread] Current Thread [Next in Thread]