bug-ncurses
[Top][All Lists]
Advanced

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

printw() and pthreads


From: ChCarver
Subject: printw() and pthreads
Date: Fri, 14 Dec 2007 15:01:41 -0800 (PST)

Problem: When using printw() and a thread interuppt happens sometimes I get a
double character on the screen.

Example: If I type "Hello World" what gets put out is "Helloo World". This
only happens when threads swap.

Situation: I have two threads running, one is a console thread and one is a
keyboard thread. The console thread reads from a standard UNIX message queue
to display information to a NCURSES window. The keyboard thread reads input
from the keyboard and stores the information into a buffer. Now both threads
communicate via shared memory as to know whether if it can display
information to the console. The keyboard thread can read in keyboard input
with echo off and will only display the character is the console thread is
not outputing information to the console. And if something is being keyed
into the keyboard and the keyboard thread has control of the console, then
the console thread waits to display data.

Now the keyboard thread when it gets a character uses printw() to display a
single character at a time as it's typed. Right now the console thread has
nothing to be displayed. But it's there and the threads do swap from time to
time.  Every once and while I'll be typing and I see a double letter getting
displayed. WhenI hit the KEY_ENTER or the 0x0a key the code then displays
what's in my internal buffer and sure enough the double character on the
screen is not present.

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. 

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?

Thank you for any help, insight, advice, or answers.

-- Chris
-- 
View this message in context: 
http://www.nabble.com/printw%28%29-and-pthreads-tp14339842p14339842.html
Sent from the Gnu - Ncurses mailing list archive at Nabble.com.





reply via email to

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