unofficial mirror of guile-user@gnu.org 
 help / color / mirror / Atom feed
From: vimml@selgrad.org
To: guile-user@gnu.org
Subject: scm_shell in C-Thread - Quit vs. Terminal Corruption
Date: Fri, 16 Oct 2009 21:09:25 +0200	[thread overview]
Message-ID: <20091016190925.GA26534@shoikan> (raw)

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	other threads:[~2009-10-16 19:09 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-10-16 19:09 vimml [this message]
2009-10-17  2:42 ` scm_shell in C-Thread - Quit vs. Terminal Corruption Linas Vepstas
2009-10-17 17:36   ` kai.selgrad
2009-10-18 15:05     ` Neil Jerram
2009-10-18 15:48       ` kai.selgrad
2009-10-17  2:49 ` Linas Vepstas
2009-10-17 12:44   ` Ludovic Courtès
2009-10-17 17:43     ` vimml
2009-10-17 17:47   ` vimml
2009-10-17 12:52 ` Ludovic Courtès

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/guile/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20091016190925.GA26534@shoikan \
    --to=vimml@selgrad.org \
    --cc=guile-user@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).