bug-ncurses
[Top][All Lists]
Advanced

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

Re: Multi-threaded output


From: Thomas Dickey
Subject: Re: Multi-threaded output
Date: Mon, 25 Oct 2004 20:12:46 -0400 (EDT)

On Mon, 25 Oct 2004, Steven Seeger wrote:

> On 10/25/04 4:16 PM, "Thomas Dickey" <address@hidden> wrote:
>
> Hi Thomas. Thanks for writing me back.
> >
> > ncurses isn't thread-safe.  Occasionally someone asks about it, but no
> > one's done any work to make this happen.
>
> Not me. :)

It's probably worth the effort (I've found no lack of other things to
do, however).

> > getch does a refresh.  If your other threads are running concurrently
> > and updating the screen, it won't work.
>
> Perhaps getch is corrupting my screen? I didn't put a mutex around it as I

That's my offhand guess.  getch does a refresh before it settles down
to wait for input.  There's also the (less-used) path in getch which
makes it echo input as it's read, which also requires refresh.

> didn't think I had to, as it blocks until input comes in, and the thread
> that's drawing the screen has a higher priority than the one calling getch
> so I figured the getch thread wouldn't run until the higher priority draw
> one is finished.
>
> >
> > If you added a mutex to refresh and getch, there's still the places
> > that would update the screen (a lot of places).  Probably the simplest
> > way to go would be to add an entrypoint to ncurses that provides the
> > mutex, use that in blocks of code that would do updates.  That way
> > you wouldn't be locking/unlocking things down at the character level.
>
> What do you mean by add an entry point?

A function.  I haven't looked at threads for quite a while, but as I
recall it, you can make a mutex by associating it with a user-supplied
variable.  A function that would do either the lock or unlock depending
on a second parameter would be usable also by getch, e.g., if you made
the variable something like the WINDOW* which it uses as a parameter.

Something like that (particularly if its interface didn't introduce new
datatypes or includes) would be useful as an extension to ncurses.  Aside
from the WINDOW's, the other global variables that come to mind (COLS,
LINES) which are frequently used could be replaced by macros that evaluate
to functions which wrap a mutex, e.g., to prevent one thread from resizing
the screen while another is repainting.

-- 
Thomas E. Dickey
http://invisible-island.net
ftp://invisible-island.net




reply via email to

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