bug-ncurses
[Top][All Lists]
Advanced

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

Re: printw() and pthreads


From: Christopher Carver
Subject: Re: printw() and pthreads
Date: Mon, 17 Dec 2007 14:49:58 -0600

Thank you Thomas Dickey. My calls are wrapped by a shared mutex amongst
the threads. I went ahead with using mvaddch() and this has addressed
the issue, but now I have to do a bit more management for the console on
my end. Which is perfectly fine as getting a duplicate character on a
screen is very distracting. So the extra logic on my end is completely
fine.

If you are getting into a recursive mutex lock, see if you can use
pthread_mutex_trylock() and that _might_ help you. My rule of thumb and
it's not an absolute hard rule, but all my threads call non-blocking or
asynchronous functions. It solves so many headaches! And I found
pthread_mutex_trylock() is a great way to deal with recursive mutex
locks.

-- Chris


On Sun, 2007-12-16 at 19:11 -0500, Thomas Dickey wrote:
> On Fri, 14 Dec 2007, ChCarver wrote:
> 
> > I believe the issue is inside printw(). That when the thread is suspended
> > for the console thread and then returned a duplicate character is placed to
> > the screen.
> 
> Actually it sounds as if you're going into the display code more than
> once.  You're presumably aware that ncurses is not thread-safe(*) - have
> to wrap your calls appropriately.
> 
> > Question: To get around this will I need to start using mvaddch() as that
> > places the character at an absolute position, where as printw() might be
> > incrementing a position. The reason I went with printw() was it handled the
> > scrolling for me. If I start using mvaddch(), how do I get the window to
> > still scroll to the next line?
> 
> addch would wrap - but combined with moving on each addch call, that's
> not straightforward...
> 
> (*) I've been making changes in that area, but am stuck on a change where
>      a recursive mutex is blocking itself ;-)
> 





reply via email to

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