curs_threads(3X)
β¨ NAME β¨
okay so bestie, this is the curs_threads(3X) page from the Library calls section, and it's all about curses support for multi-threaded applications. The whole squad is NCURSES_WINDOW_CB, NCURSES_SCREEN_CB, get_escdelay, set_escdelay, set_tabsize, use_screen, and use_window. π
β¨ SYNOPSIS β¨
#include <curses.h>
/* data types */
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 β¨
okay so the tea: the ncurses library can be configured to support multi-threaded applications in a rudimentary way. That configuration produces a different set of libraries β named libncursest, for example β since doing so alters ncurses's application binary interface (ABI). periodt.
Instead of modifying the programming interface (API) to make ncurses functions expect an additional argument specifying a thread, the library adds functions, usable in any configuration, that hide the mutexes (mutual exclusion locks) needed to prevent concurrent access to variables shared by multiple threads of execution. no cap, it's giving lock magic. π
ncurses threading support requires the use of functions to access members of the WINDOW structure (see curs_opaque(3X)). It further makes functions of the common global variables COLORS, COLOR_PAIRS, COLS, ESCDELAY, LINES, TABSIZE, curscr, newscr, and ttytype, maintaining them as read-only values in the SCREEN structure. obsessed with this level of organization.
Even this is not enough to make an application using curses thread-safe. We would expect a multi-threaded application to have threads updating separate windows (on the same device), and separate screens (on different devices). Further, applications expect a few of the global variables to be writable. The functions described here address these special situations. main character energy for real.
The ESCDELAY and TABSIZE global variables are modified by some applications. To modify them in any configuration, use the set_escdelay or set_tabsize functions. Other global variables are not modifiable. get_escdelay retrieves ESCDELAY's value. π
The use_window and use_screen functions provide coarse-grained mutexes for their respective WINDOW and SCREEN parameters; they call a user-supplied function, pass it a data parameter, and return the value from the user-supplied function to the application. so handy, honestly.
π¦ Usage π¦
All ncurses library functions assume that the locale is not altered during operation. In addition, they use data that is maintained within a hierarchy of scopes. vibe check: here's the hierarchy.
- global data used in the low-level
terminfoortermcapinterfaces - terminal data associated with a call to
set_curterm(3X)Terminal data are initialized when screens are created. - screen data associated with a call to
newterm(3X)orinitscr(3X) - window data associated with a call to
newwin(3X)orsubwin(3X)Windows are associated with screens. Pads are not necessarily associated with any particular screen. Mostcursesapplications operate on one or more windows within a single screen. - reentrant data associated with βpureβ functions that alter no shared variables
The following table lists the scope of each symbol in the ncurses library when configured to support multi-threaded applications. π
okay bestie, deep breath, because this is THE LIST π every single symbol in this entire API, plus the scope it lives in. it's giving seating chart for the most unhinged group project of all time: some of these are global, some are out here living on a screen, some are window girlies, some belong to the terminal, and a few are reentrant because they're just built different β¨
we are going through every last one. no skipping, no shortcuts, no "eh, you get the idea". you WILL know exactly where every symbol lives. periodt.
BCβ globalCOLORSβ screen (read-only)COLOR_PAIRβ reentrantCOLOR_PAIRSβ screen (read-only)COLSβ screen (read-only)ESCDELAYβ screen (read-only; seeset_escdelay)LINESβ screen (read-only)PAIR_NUMBERβ reentrantPCβ globalSPβ globalTABSIZEβ screen (read-only; seeset_tabsize)UPβ globalacs_mapβ screen (read-only)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β screenattr_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β screenbeepβ screen β she goes beep πbkgdβ window (stdscr)bkgdsetβ window (stdscr)bkgrndβ window (stdscr)bkgrndsetβ window (stdscr)boolcodesβ global (read-only)boolfnamesβ global (read-only)boolnamesβ global (read-only)borderβ window (stdscr)border_setβ window (stdscr)boxβ window (stdscr)box_setβ window (stdscr)can_change_colorβ terminalcbreakβ screenchgatβ window (stdscr)clearβ window (stdscr)clearokβ windowclrtobotβ window (stdscr)clrtoeolβ window (stdscr)color_contentβ screencolor_setβ window (stdscr)copywinβ window (locks source, target) β locks BOTH of them, no sneaking in πcur_termβ terminalcurs_setβ screencurscrβ screen (read-only)curses_versionβ global (read-only)def_prog_modeβ terminaldef_shell_modeβ terminaldefine_keyβ screendel_curtermβ screendelay_outputβ screendelchβ window (stdscr)deletelnβ window (stdscr)delscreenβ global (locks screen list, screen) β two locks at once, thorough queen πdelwinβ global (locks window list)derwinβ screendoupdateβ screendupwinβ screen (locks window)echoβ screenecho_wcharβ window (stdscr)echocharβ window (stdscr)endwinβ screen β and scene π¬eraseβ window (stdscr)erasecharβ window (stdscr)erasewcharβ window (stdscr)filterβ globalflashβ terminal β she goes flash β‘flushinpβ screenget_wchβ screen (input operation)get_wstrβ screen (input operation)getattrsβ windowgetbegxβ windowgetbegyβ windowgetbkgdβ windowgetbkgrndβ windowgetccharβ reentrantgetchβ screen (input operation)getcurxβ windowgetcuryβ windowgetmaxxβ windowgetmaxyβ windowgetmouseβ screen (input operation)getn_wstrβ screen (input operation)getnstrβ screen (input operation)getparxβ windowgetparyβ windowgetstrβ screen (input operation)getwinβ screen (input operation)halfdelayβ screenhas_colorsβ terminalhas_icβ terminalhas_ilβ terminalhas_keyβ screenhlineβ window (stdscr)hline_setβ window (stdscr)idcokβ windowidlokβ windowimmedokβ windowin_wchβ window (stdscr)in_wchnstrβ window (stdscr)in_wchstrβ window (stdscr)inchβ window (stdscr)inchnstrβ window (stdscr)inchstrβ window (stdscr)init_colorβ screeninit_pairβ screeninitscrβ global (locks screen list) β the main character herself, obviously π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β terminalinwstrβ window (stdscr)is_clearedβ windowis_idcokβ windowis_idlokβ windowis_immedokβ windowis_keypadβ windowis_leaveokβ windowis_linetouchedβ windowis_nodelayβ windowis_notimeoutβ windowis_scrollokβ windowis_syncokβ windowis_term_resizedβ terminalis_wintouchedβ windowisendwinβ screenkey_definedβ screenkey_nameβ global (static data) β static data, so mind your business πkeyboundβ screenkeynameβ global (static data)keyokβ screenkeypadβ windowkillcharβ terminalkillwcharβ terminalleaveokβ windowlongnameβ screenmcprintβ terminalmetaβ screenmouse_trafoβ window (stdscr)mouseintervalβ screenmousemaskβ screenmoveβ 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β screenmvdelchβ 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β screenmvvlineβ window (stdscr)mvvline_setβ window (stdscr)mvwadd_wchβ windowmvwadd_wchnstrβ windowmvwadd_wchstrβ windowmvwaddchβ windowmvwaddchnstrβ windowmvwaddchstrβ windowmvwaddnstrβ windowmvwaddnwstrβ windowmvwaddstrβ windowmvwaddwstrβ windowmvwchgatβ windowmvwdelchβ windowmvwget_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β windowmvwhline_setβ windowmvwinβ windowmvwin_wchβ windowmvwin_wchnstrβ windowmvwin_wchstrβ windowmvwinchβ windowmvwinchnstrβ windowmvwinchstrβ windowmvwinnstrβ windowmvwinnwstrβ windowmvwins_nwstrβ windowmvwins_wchβ windowmvwins_wstrβ windowmvwinschβ windowmvwinsnstrβ windowmvwinsstrβ windowmvwinstrβ windowmvwinwstrβ windowmvwprintwβ windowmvwscanwβ screenmvwvlineβ windowmvwvline_setβ windownapmsβ reentrant β nap time bestie, love that for her π΄newpadβ global (locks window list)newscrβ screen (read-only)newtermβ global (locks screen list)newwinβ global (locks window list)nlβ screennocbreakβ screennodelayβ windownoechoβ screennofilterβ globalnonlβ screennoqiflushβ terminalnorawβ screennotimeoutβ windownumcodesβ global (read-only)numfnamesβ global (read-only)numnamesβ global (read-only)ospeedβ globaloverlayβ window (locks source, target) β double lock again, she's not playing πoverwriteβ window (locks source, target)pair_contentβ screenpecho_wcharβ screenpechocharβ screenpnoutrefreshβ screenprefreshβ screenprintwβ window
β¦and the list keeps going, bestie, we're not even close to done yet π
putpβ globalputwinβ windowqiflushβ terminalrawβ screenredrawwinβ windowrefreshβ screenreset_prog_modeβ screenreset_shell_modeβ screenresettyβ terminalresize_termβ screen (locks window list)resizetermβ screenrestarttermβ screenripofflineβ global (static data)savettyβ terminalscanwβ screenscr_dumpβ screenscr_initβ screenscr_restoreβ screenscr_setβ screenscrlβ window (stdscr)scrollβ windowscrollokβ windowset_curtermβ screenset_escdelayβ screenset_tabsizeβ screenset_termβ global (locks screen list, screen)setccharβ reentrantsetscrregβ window (stdscr)setuptermβ globalslk_attrβ screenslk_attr_offβ screenslk_attr_onβ screenslk_attr_setβ screenslk_attroffβ screenslk_attronβ screenslk_attrsetβ screenslk_clearβ screenslk_colorβ screenslk_initβ screenslk_labelβ screenslk_noutrefreshβ screenslk_refreshβ screenslk_restoreβ screenslk_setβ screenslk_touchβ screenslk_wsetβ screenstandendβ windowstandoutβ windowstart_colorβ screenstdscrβ screen (read-only)strcodesβ global (read-only)strfnamesβ global (read-only)strnamesβ global (read-only)subpadβ windowsubwinβ windowsyncokβ windowterm_attrsβ screentermattrsβ screentermnameβ terminaltgetentβ globaltgetflagβ globaltgetnumβ globaltgetstrβ globaltgotoβ globaltigetflagβ terminaltigetnumβ terminaltigetstrβ terminaltimeoutβ window (stdscr)touchlineβ windowtouchwinβ windowtparmβ global (static data)tputsβ screentraceβ global (static data)ttytypeβ screen (read-only)typeaheadβ screenunctrlβ screenunget_wchβ screen (input operation)ungetchβ screen (input operation)ungetmouseβ screen (input operation)untouchwinβ windowuse_default_colorsβ screenuse_envβ global (static data)use_extended_namesβ global (static data)use_legacy_codingβ screenuse_screenβ global (locks screen list, screen)use_windowβ global (locks window list, window)vid_attrβ screenvid_putsβ screenvidattrβ screenvidputsβ screenvlineβ window (stdscr)vline_setβ window (stdscr)vw_printwβ windowvw_scanwβ screenvwprintwβ windowvwscanwβ screenwadd_wchβ windowwadd_wchnstrβ windowwadd_wchstrβ windowwaddchβ windowwaddchnstrβ windowwaddchstrβ windowwaddnstrβ windowwaddnwstrβ windowwaddstrβ windowwaddwstrβ windowwattr_getβ windowwattr_offβ windowwattr_onβ windowwattr_setβ windowwattroffβ windowwattronβ windowwattrsetβ windowwbkgdβ windowwbkgdsetβ windowwbkgrndβ windowwbkgrndsetβ windowwborderβ windowwborder_setβ windowwchgatβ windowwclearβ windowwclrtobotβ windowwclrtoeolβ windowwcolor_setβ windowwcursyncupβ screen (affects window plus parents)wdelchβ windowwdeletelnβ windowwecho_wcharβ windowwechocharβ windowwencloseβ windowweraseβ windowwget_wchβ screen (input operation)wget_wstrβ screen (input operation)wgetbkgrndβ windowwgetchβ screen (input operation)wgetdelayβ windowwgetn_wstrβ screen (input operation)wgetnstrβ screen (input operation)wgetparentβ windowwgetscrregβ windowwgetstrβ screen (input operation)whlineβ windowwhline_setβ windowwin_wchβ windowwin_wchnstrβ windowwin_wchstrβ windowwinchβ windowwinchnstrβ windowwinchstrβ windowwinnstrβ windowwinnwstrβ windowwins_nwstrβ windowwins_wchβ windowwins_wstrβ windowwinschβ windowwinsdellnβ windowwinsertlnβ windowwinsnstrβ windowwinsstrβ windowwinstrβ windowwinwstrβ windowwmouse_trafoβ windowwmoveβ windowwnoutrefreshβ screenwprintwβ windowwredrawlnβ windowwrefreshβ screenwresizeβ window (locks window list)wscanwβ screenwscrlβ windowwsetscrregβ windowwstandendβ windowwstandoutβ windowwsyncdownβ screen (affects window plus parents)wsyncupβ screen (affects window plus parents)wtimeoutβ windowwtouchlnβ windowwunctrlβ global (static data)wvlineβ windowwvline_setβ window
β¨ RETURN VALUE β¨
Okay so here's what you actually get back, bestie π
get_escdelayhands you the value ofESCDELAY. that's it, that's the whole vibe.set_escdelayandset_tabsizegive youERRif it flops andOKif it ate and left no crumbs βuse_screenanduse_windowreturn theintthat the user-supplied function you passed them gives back β so like, whatever your lil callback returns, that's what comes out. no middleman behavior, no cap π«Ά
π NOTES π
Real talk for a sec: ncurses gives you both a C function and a preprocessor macro for every single function documented on this page. two for the price of one, we love a generous queen π
π PORTABILITY π
Heads up, bestie β these routines are specific to ncurses. They were not supported on Version 7, BSD or System V implementations.
So if your code is leaning on these ncurses extensions, the move is to condition it using NCURSES_VERSION. protect your peace (and your portability) fr fr π§
π SEE ALSO π
curses(3X)curs_opaque(3X)curs_variables(3X)
And that's a wrap on the whole page, babes π this was ncurses 6.6, dated 2025-02-15, and the manual section is curs_threads(3X). go forth and thread safely, my icon πβ¨
π¦ where this page comes from
- alpine 3.24: ncurses-doc 6.6_p20260516-r0 Β· X11
- arch rolling: ncurses 6.6-2 Β· MIT-open-group
- fedora 44: ncurses-devel 6.6-1.fc44 Β· MIT-open-group
- fedora 44: ncurses-devel 6.6-1.fc44 Β· MIT-open-group
- Copyright 2021-2024,2025 Thomas E. Dickey
- Copyright 2008-2015,2017 Free Software Foundation, Inc
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms