bug-ncurses
[Top][All Lists]
Advanced

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

Re: printw() and pthreads


From: Thomas Dickey
Subject: Re: printw() and pthreads
Date: Mon, 17 Dec 2007 19:19:18 -0500
User-agent: Mutt/1.5.17 (2007-11-01)

On Mon, Dec 17, 2007 at 02:49:58PM -0600, Christopher Carver wrote:
> 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.

right.  The work I'm doing is to (attempt-to...) make a new flavor of
the ncurses library that can be used to simplify use in a multi-threaded
application (basically just wrap a mutex around a block of operations on
a WINDOW or on a SCREEN).  The part I'm stuck on is in the changes to
delwin - which seems to be the main thread running into an obstacle
after the child threads claim to have exited.
 
> 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.

I do know about the pthread_mutex_trylock() function, but it doesn't
seem appropriate for cases where there may be a race.  That, plus
some natural recursion in the chunk of code I'm working on was why
I wanted to use the nested mutex call.

> 
> -- 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 ;-)
> > 

-- 
Thomas E. Dickey <address@hidden>
http://invisible-island.net
ftp://invisible-island.net

Attachment: signature.asc
Description: Digital signature


reply via email to

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