threads(3NCURSES)

πŸ“¦
version 6.4 Β· 2 versions
, in debian bookworm

✨ threads(3NCURSES) ✨

okay bestie, welcome to the threads page from the 3NCURSES manual πŸ’– this one's a whole trilogy so buckle up, we're doing part one rn πŸŽ€


🌸 NAME 🌸

curs_threads β€” curses thread support


πŸ¦‹ SYNOPSIS πŸ¦‹

#include <curses.h>

typedef int (*NCURSES_WINDOW_CB)(WINDOW *, void *);
typedef int (*NCURSES_SCREEN_CB)(SCREEN *, void *);

int get_escdelay(void);
int set_escdelay(int ms);
int set_tabsize(int cols);

int use_screen(SCREEN *scr, NCURSES_SCREEN_CB func, void *data);
int use_window(WINDOW *win, NCURSES_WINDOW_CB func, void *data);

πŸ’… DESCRIPTION πŸ’…

so this implementation can be configured to give you rudimentary support for multi-threaded apps 🧡✨. that means a different set of libraries, like libncursest, because the binary interfaces are different, periodt.

instead of going around and changing every single interface to pass a thread specifier to each function (imagine the chaos 😭), it just adds a few functions that work in any configuration. these lil guys hide the mutexes you'd need to stop concurrent use of the global variables when you're configured for threading πŸ‘‘

on top of forcing access to members of the WINDOW structure to go through functions (peep opaque(3NCURSES) for that tea πŸ«–), it also turns the common global variables into functions β€” like COLORS, COLOR_PAIRS, COLS, ESCDELAY, LINES, TABSIZE, curscr, newscr and ttytype 🌈. those variables are maintained as read-only values, stored inside the SCREEN structure. no cap.

and even that isn't enough to make a thread-safe app using curses, bestie πŸ’€. a multi-threaded application would be expected to have threads updating separate windows (within the same device), or updating on separate screens (on different devices). also, a few of the global variables are considered writable by some applications πŸ™ˆ. the functions described here are the ones that address these special situations.

the ESCDELAY and TABSIZE global variables get modified by some applications. to modify them in any configuration, use the set_escdelay or set_tabsize functions ⭐. other global variables are not modifiable, sorry babes.

the get_escdelay function returns the value for ESCDELAY πŸ’–.

the use_window and use_screen functions provide coarse granularity mutexes for their respective WINDOW and SCREEN parameters, and call a user-supplied function, passing it a data parameter, and returning the value from the user-supplied function back to the application πŸ”₯.


πŸŽ€ USAGE πŸŽ€

all of the ncurses library functions assume that the locale is not altered during operation. plus, they use data that's maintained within a hierarchy of scopes πŸ‘‘:

  • global data, e.g., used in the low-level terminfo or termcap interfaces.
  • terminal data, e.g., associated with a call to set_curterm. the terminal data are initialized when screens are created.
  • screen data, e.g., associated with a call to newterm or initscr.
  • window data, e.g., associated with a call to newwin or subwin. windows are associated with screens. pads are not necessarily associated with a particular screen.
    • most curses applications operate on one or more windows within a single screen.
  • reentrant, i.e., it uses only the data passed as parameters.

more parts coming bestie, don't go anywhere 🫢✨

Okay so bestie, this table lists the scope of data used for each symbol in the ncurses library when it's configured to support threading. It's literally the "who owns what" cheat sheet, and you know we love a good org chart. πŸ’…

For each symbol, here's its scope:

  • BC β€” global
  • COLORS β€” screen (readonly)
  • COLOR_PAIR β€” reentrant
  • COLOR_PAIRS β€” screen (readonly)
  • COLS β€” screen (readonly)
  • ESCDELAY β€” screen (readonly, see set_escdelay)
  • LINES β€” screen (readonly)
  • PAIR_NUMBER β€” reentrant
  • PC β€” global
  • SP β€” global
  • TABSIZE β€” screen (readonly)
  • UP β€” global
  • acs_map β€” screen (readonly)
  • add_wch β€” window (stdscr)
  • add_wchnstr β€” window (stdscr)
  • add_wchstr β€” window (stdscr)
  • addch β€” window (stdscr)
  • addchnstr β€” window (stdscr)
  • addchstr β€” window (stdscr)
  • addnstr β€” window (stdscr)
  • addnwstr β€” window (stdscr)
  • addstr β€” window (stdscr)
  • addwstr β€” window (stdscr)
  • assume_default_colors β€” screen
  • attr_get β€” window (stdscr)
  • attr_off β€” window (stdscr)
  • attr_on β€” window (stdscr)
  • attr_set β€” window (stdscr)
  • attroff β€” window (stdscr)
  • attron β€” window (stdscr)
  • attrset β€” window (stdscr)
  • baudrate β€” screen
  • beep β€” screen
  • bkgd β€” window (stdscr)
  • bkgdset β€” window (stdscr)
  • bkgrnd β€” window (stdscr)
  • bkgrndset β€” window (stdscr)
  • boolcodes β€” global (readonly)
  • boolfnames β€” global (readonly)
  • boolnames β€” global (readonly)
  • border β€” window (stdscr)
  • border_set β€” window (stdscr)
  • box β€” window (stdscr)
  • box_set β€” window (stdscr)
  • can_change_color β€” terminal
  • cbreak β€” screen
  • chgat β€” window (stdscr)
  • clear β€” window (stdscr)
  • clearok β€” window
  • clrtobot β€” window (stdscr)
  • clrtoeol β€” window (stdscr)
  • color_content β€” screen
  • color_set β€” window (stdscr)
  • copywin β€” window locks(source, target)
  • cur_term β€” terminal
  • curs_set β€” screen
  • curscr β€” screen (readonly)
  • curses_version β€” global (readonly)
  • def_prog_mode β€” terminal
  • def_shell_mode β€” terminal
  • define_key β€” screen
  • del_curterm β€” screen
  • delay_output β€” screen
  • delch β€” window (stdscr)
  • deleteln β€” window (stdscr)
  • delscreen β€” global locks(screenlist, screen)
  • delwin β€” global locks(windowlist)
  • derwin β€” screen
  • doupdate β€” screen
  • dupwin β€” screen locks(window)
  • echo β€” screen
  • echo_wchar β€” window (stdscr)
  • echochar β€” window (stdscr)
  • endwin β€” screen
  • erase β€” window (stdscr)
  • erasechar β€” window (stdscr)
  • erasewchar β€” window (stdscr)
  • filter β€” global
  • flash β€” terminal
  • flushinp β€” screen
  • get_wch β€” screen (input-operation)
  • get_wstr β€” screen (input-operation)
  • getattrs β€” window
  • getbegx β€” window
  • getbegy β€” window
  • getbkgd β€” window
  • getbkgrnd β€” window
  • getcchar β€” reentrant
  • getch β€” screen (input-operation)
  • getcurx β€” window
  • getcury β€” window
  • getmaxx β€” window
  • getmaxy β€” window
  • getmouse β€” screen (input-operation)
  • getn_wstr β€” screen (input-operation)
  • getnstr β€” screen (input-operation)
  • getparx β€” window
  • getpary β€” window
  • getstr β€” screen (input-operation)
  • getwin β€” screen (input-operation)
  • halfdelay β€” screen
  • has_colors β€” terminal
  • has_ic β€” terminal
  • has_il β€” terminal
  • has_key β€” screen
  • hline β€” window (stdscr)
  • hline_set β€” window (stdscr)
  • idcok β€” window
  • idlok β€” window
  • immedok β€” window
  • in_wch β€” window (stdscr)
  • in_wchnstr β€” window (stdscr)
  • in_wchstr β€” window (stdscr)
  • inch β€” window (stdscr)
  • inchnstr β€” window (stdscr)
  • inchstr β€” window (stdscr)
  • init_color β€” screen
  • init_pair β€” screen
  • initscr β€” global locks(screenlist)
  • innstr β€” window (stdscr)
  • innwstr β€” window (stdscr)
  • ins_nwstr β€” window (stdscr)
  • ins_wch β€” window (stdscr)
  • ins_wstr β€” window (stdscr)
  • insch β€” window (stdscr)
  • insdelln β€” window (stdscr)
  • insertln β€” window (stdscr)
  • insnstr β€” window (stdscr)
  • insstr β€” window (stdscr)
  • instr β€” window (stdscr)
  • intrflush β€” terminal
  • inwstr β€” window (stdscr)
  • is_cleared β€” window
  • is_idcok β€” window
  • is_idlok β€” window
  • is_immedok β€” window
  • is_keypad β€” window
  • is_leaveok β€” window
  • is_linetouched β€” window
  • is_nodelay β€” window
  • is_notimeout β€” window
  • is_scrollok β€” window
  • is_syncok β€” window
  • is_term_resized β€” terminal
  • is_wintouched β€” window
  • isendwin β€” screen
  • key_defined β€” screen
  • key_name β€” global (static data)
  • keybound β€” screen
  • keyname β€” global (static data)
  • keyok β€” screen
  • keypad β€” window
  • killchar β€” terminal
  • killwchar β€” terminal
  • leaveok β€” window
  • longname β€” screen
  • mcprint β€” terminal
  • meta β€” screen
  • mouse_trafo β€” window (stdscr)
  • mouseinterval β€” screen
  • mousemask β€” screen
  • move β€” window (stdscr)
  • mvadd_wch β€” window (stdscr)
  • mvadd_wchnstr β€” window (stdscr)
  • mvadd_wchstr β€” window (stdscr)
  • mvaddch β€” window (stdscr)
  • mvaddchnstr β€” window (stdscr)
  • mvaddchstr β€” window (stdscr)
  • mvaddnstr β€” window (stdscr)
  • mvaddnwstr β€” window (stdscr)
  • mvaddstr β€” window (stdscr)
  • mvaddwstr β€” window (stdscr)
  • mvchgat β€” window (stdscr)
  • mvcur β€” screen
  • mvdelch β€” window (stdscr)
  • mvderwin β€” window (stdscr)
  • mvget_wch β€” screen (input-operation)
  • mvget_wstr β€” screen (input-operation)
  • mvgetch β€” screen (input-operation)
  • mvgetn_wstr β€” screen (input-operation)
  • mvgetnstr β€” screen (input-operation)
  • mvgetstr β€” screen (input-operation)
  • mvhline β€” window (stdscr)
  • mvhline_set β€” window (stdscr)
  • mvin_wch β€” window (stdscr)
  • mvin_wchnstr β€” window (stdscr)
  • mvin_wchstr β€” window (stdscr)
  • mvinch β€” window (stdscr)
  • mvinchnstr β€” window (stdscr)
  • mvinchstr β€” window (stdscr)
  • mvinnstr β€” window (stdscr)
  • mvinnwstr β€” window (stdscr)
  • mvins_nwstr β€” window (stdscr)
  • mvins_wch β€” window (stdscr)
  • mvins_wstr β€” window (stdscr)
  • mvinsch β€” window (stdscr)
  • mvinsnstr β€” window (stdscr)
  • mvinsstr β€” window (stdscr)
  • mvinstr β€” window (stdscr)
  • mvinwstr β€” window (stdscr)
  • mvprintw β€” window (stdscr)
  • mvscanw β€” screen
  • mvvline β€” window (stdscr)
  • mvvline_set β€” window (stdscr)
  • mvwadd_wch β€” window
  • mvwadd_wchnstr β€” window
  • mvwadd_wchstr β€” window
  • mvwaddch β€” window
  • mvwaddchnstr β€” window
  • mvwaddchstr β€” window
  • mvwaddnstr β€” window
  • mvwaddnwstr β€” window
  • mvwaddstr β€” window
  • mvwaddwstr β€” window
  • mvwchgat β€” window
  • mvwdelch β€” window
  • mvwget_wch β€” screen (input-operation)
  • mvwget_wstr β€” screen (input-operation)
  • mvwgetch β€” screen (input-operation)
  • mvwgetn_wstr β€” screen (input-operation)
  • mvwgetnstr β€” screen (input-operation)
  • mvwgetstr β€” screen (input-operation)
  • mvwhline β€” window
  • mvwhline_set β€” window
  • mvwin β€” window
  • mvwin_wch β€” window
  • mvwin_wchnstr β€” window
  • mvwin_wchstr β€” window
  • mvwinch β€” window
  • mvwinchnstr β€” window
  • mvwinchstr β€” window
  • mvwinnstr β€” window
  • mvwinnwstr β€” window
  • mvwins_nwstr β€” window
  • mvwins_wch β€” window
  • mvwins_wstr β€” window
  • mvwinsch β€” window
  • mvwinsnstr β€” window
  • mvwinsstr β€” window
  • mvwinstr β€” window
  • mvwinwstr β€” window
  • mvwprintw β€” window
  • mvwscanw β€” screen
  • mvwvline β€” window
  • mvwvline_set β€” window
  • napms β€” reentrant (she naps, she's safe, iconic πŸ’€)
  • newpad β€” global locks(windowlist)
  • newscr β€” screen (readonly)
  • newterm β€” global locks(screenlist)
  • newwin β€” global locks(windowlist)
  • nl β€” screen
  • nocbreak β€” screen
  • nodelay β€” window
  • noecho β€” screen
  • nofilter β€” global
  • nonl β€” screen
  • noqiflush β€” terminal
  • noraw β€” screen
  • notimeout β€” window
  • numcodes β€” global (readonly)
  • numfnames β€” global (readonly)
  • numnames β€” global (readonly)
  • ospeed β€” global
  • overlay β€” window locks(source, target)
  • overwrite β€” window locks(source, target)
  • pair_content β€” screen
  • pecho_wchar β€” screen
  • pechochar β€” screen
  • pnoutrefresh β€” screen
  • prefresh β€” screen
  • printw β€” window
  • putp β€” global
  • putwin β€” window
  • qiflush β€” terminal
  • raw β€” screen
  • redrawwin β€” window
  • refresh β€” screen (the main character fr πŸ’…)
  • reset_prog_mode β€” screen
  • reset_shell_mode β€” screen
  • resetty β€” terminal
  • resize_term β€” screen locks(windowlist)
  • resizeterm β€” screen
  • restartterm β€” screen
  • ripoffline β€” global (static data)
  • savetty β€” terminal
  • scanw β€” screen
  • scr_dump β€” screen
  • scr_init β€” screen
  • scr_restore β€” screen
  • scr_set β€” screen
  • scrl β€” window (stdscr)
  • scroll β€” window
  • scrollok β€” window
  • set_curterm β€” screen
  • set_escdelay β€” screen
  • set_tabsize β€” screen
  • set_term β€” global locks(screenlist, screen)
  • setcchar β€” reentrant
  • setscrreg β€” window (stdscr)
  • setupterm β€” global
  • slk_attr β€” screen
  • slk_attr_off β€” screen
  • slk_attr_on β€” screen
  • slk_attr_set β€” screen
  • slk_attroff β€” screen
  • slk_attron β€” screen
  • slk_attrset β€” screen
  • slk_clear β€” screen
  • slk_color β€” screen
  • slk_init β€” screen
  • slk_label β€” screen
  • slk_noutrefresh β€” screen
  • slk_refresh β€” screen
  • slk_restore β€” screen
  • slk_set β€” screen
  • slk_touch β€” screen
  • slk_wset β€” screen
  • standend β€” window
  • standout β€” window
  • start_color β€” screen
  • stdscr β€” screen (readonly)
  • strcodes β€” global (readonly)
  • strfnames β€” global (readonly)
  • strnames β€” global (readonly)
  • subpad β€” window
  • subwin β€” window
  • syncok β€” window
  • term_attrs β€” screen
  • termattrs β€” screen
  • termname β€” terminal
  • tgetent β€” global
  • tgetflag β€” global
  • tgetnum β€” global
  • tgetstr β€” global
  • tgoto β€” global
  • tigetflag β€” terminal
  • tigetnum β€” terminal
  • tigetstr β€” terminal
  • timeout β€” window (stdscr)
  • touchline β€” window
  • touchwin β€” window
  • tparm β€” global (static data)
  • tputs β€” screen
  • trace β€” global (static data)
  • ttytype β€” screen (readonly)
  • typeahead β€” screen
  • unctrl β€” screen
  • unget_wch β€” screen (input-operation)
  • ungetch β€” screen (input-operation)
  • ungetmouse β€” screen (input-operation)
  • untouchwin β€” window
  • use_default_colors β€” screen
  • use_env β€” global (static data)
  • use_extended_names β€” global (static data)
  • use_legacy_coding β€” screen
  • use_screen β€” global locks(screenlist, screen)
  • use_window β€” global locks(windowlist, window)
  • vid_attr β€” screen
  • vid_puts β€” screen
  • vidattr β€” screen
  • vidputs β€” screen
  • vline β€” window (stdscr)
  • vline_set β€” window (stdscr)
  • vw_printw β€” window
  • vw_scanw β€” screen
  • vwprintw β€” window
  • vwscanw β€” screen
  • wadd_wch β€” window
  • wadd_wchnstr β€” window
  • wadd_wchstr β€” window
  • waddch β€” window
  • waddchnstr β€” window
  • waddchstr β€” window
  • waddnstr β€” window
  • waddnwstr β€” window
  • waddstr β€” window
  • waddwstr β€” window
  • wattr_get β€” window
  • wattr_off β€” window
  • wattr_on β€” window
  • wattr_set β€” window
  • wattroff β€” window
  • wattron β€” window
  • wattrset β€” window
  • wbkgd β€” window
  • wbkgdset β€” window
  • wbkgrnd β€” window
  • wbkgrndset β€” window
  • wborder β€” window
  • wborder_set β€” window
  • wchgat β€” window
  • wclear β€” window
  • wclrtobot β€” window
  • wclrtoeol β€” window
  • wcolor_set β€” window
  • wcursyncup β€” screen (affects window plus parents)
  • wdelch β€” window
  • wdeleteln β€” window
  • wecho_wchar β€” window
  • wechochar β€” window
  • wenclose β€” window
  • werase β€” window
  • wget_wch β€” screen (input-operation)
  • wget_wstr β€” screen (input-operation)
  • wgetbkgrnd β€” window
  • wgetch β€” screen (input-operation)
  • wgetdelay β€” window
  • wgetn_wstr β€” screen (input-operation)
  • wgetnstr β€” screen (input-operation)
  • wgetparent β€” window
  • wgetscrreg β€” window
  • wgetstr β€” screen (input-operation)
  • whline β€” window
  • whline_set β€” window
  • win_wch β€” window
  • win_wchnstr β€” window
  • win_wchstr β€” window
  • winch β€” window
  • winchnstr β€” window
  • winchstr β€” window
  • winnstr β€” window
  • winnwstr β€” window
  • wins_nwstr β€” window
  • wins_wch β€” window
  • wins_wstr β€” window
  • winsch β€” window
  • winsdelln β€” window
  • winsertln β€” window
  • winsnstr β€” window
  • winsstr β€” window
  • winstr β€” window
  • winwstr β€” window
  • wmouse_trafo β€” window
  • wmove β€” window
  • wnoutrefresh β€” screen
  • wprintw β€” window
  • wredrawln β€” window
  • wrefresh β€” screen
  • wresize β€” window locks(windowlist)
  • wscanw β€” screen
  • wscrl β€” window
  • wsetscrreg β€” window
  • wstandend β€” window
  • wstandout β€” window
  • wsyncdown β€” screen (affects window plus parents)
  • wsyncup β€” screen (affects window plus parents)
  • wtimeout β€” window
  • wtouchln β€” window
  • wunctrl β€” global (static data)
  • wvline β€” window
  • wvline_set β€” window

okay bestie, that's the ENTIRE roster, no skips, no shortcuts, every single name accounted for 🫢 take a breath, hydrate, you ate that.


πŸ’– RETURN VALUE πŸ’–

Every one of these bad boys returns TRUE or FALSE β€” that's the whole personality β€” except the ones that say otherwise up in the notes. no cap.


πŸ“ NOTES πŸ“

For each and every name listed here, you get both a macro and a function. two for one, lowkey generous of them πŸ’…


🧳 PORTABILITY 🧳

so here's the tea β€” these routines are ncurses-specific. like, they're ncurses originals. they were not supported on Version 7, BSD or System V implementations. not a vibe on those old systems, they simply weren't invited.

It is recommended that any code depending on ncurses extensions be conditioned using NCURSES_VERSION. like, wrap it, gate it, protect it β€” do not just rawdog these calls into portable code bestie 😭

πŸ‘€ SEE ALSO πŸ‘€

  • ncurses(3NCURSES)
  • opaque(3NCURSES)
  • curses_variables(3NCURSES)

and that's a wrap on threads(3NCURSES) πŸŽ€ that's the page name sitting pretty in the footer, and fr fr you just read the whole thing β€” main character energy, no notes, go forth and thread safely βœ¨πŸ’œ

πŸ“¦ where this page comes from
  • debian bookworm: ncurses-doc 6.4-4 Β· MIT/X11
  • πŸ’– girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms