---
name: "curs_threads"
section: "3x"
platform: "linux"
package: "ncurses"
version: "6.6-2"
release: "Arch Linux 2026-11-01"
platforms: ["linux", "macos"]
url: "https://new.carta.tech/curs_threads/3x"
---

# curs\_threads(3x)

curses support for multi-threaded applications

## NAME

*NCURSES\_WINDOW\_CB*, *NCURSES\_SCREEN\_CB*, **get\_escdelay**, **set\_escdelay**, **set\_tabsize**, **use\_screen**, **use\_window** - *curses* support for multi-threaded applications

## 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

**The** *ncurses* **library can be configured to support multi-threaded** **applications in a rudimentary way.** **Such configuration produces a different set of libraries,** **named** *libncursest***,** **for example,** **since doing so alters** *ncurses***'s application binary interface** **(ABI).**

**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.**

*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.**

**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.**

**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.**

### 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.**

- •

  **global data used in the low-level** *terminfo* **or** *termcap* **interfaces**

- •

  **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) or** **initscr(3X)**

- •

  **window data associated with a call to newwin(3X) or** **subwin(3X)**

-

  **Windows are associated with screens.** **Pads are not necessarily associated with any particular screen.**

-

  **Most** *curses* **applications 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.**

| | |
| --- | --- |
| **Symbol** | **Scope** |
| **BC** | global |
| **COLORS** | screen (read-only) |
| **COLOR\_PAIR** | reentrant |
| **COLOR\_PAIRS** | screen (read-only) |
| **COLS** | screen (read-only) |
| **ESCDELAY** | screen (read-only; see **set\_escdelay**) |
| **LINES** | screen (read-only) |
| **PAIR\_NUMBER** | reentrant |
| **PC** | global |
| **SP** | global |
| **TABSIZE** | screen (read-only; see **set\_tabsize**) |
| **UP** | global |
| **acs\_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** | 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 (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** | 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 (read-only) |
| **curses\_version** | global (read-only) |
| **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 screen list, screen) |
| **delwin** | global (locks window list) |
| **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 screen list) |
| **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 |
| **newpad** | global (locks window list) |
| **newscr** | screen (read-only) |
| **newterm** | global (locks screen list) |
| **newwin** | global (locks window list) |
| **nl** | screen |
| **nocbreak** | screen |
| **nodelay** | window |
| **noecho** | screen |
| **nofilter** | global |
| **nonl** | screen |
| **noqiflush** | terminal |
| **noraw** | screen |
| **notimeout** | window |
| **numcodes** | global (read-only) |
| **numfnames** | global (read-only) |
| **numnames** | global (read-only) |
| **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 |
| **reset\_prog\_mode** | screen |
| **reset\_shell\_mode** | screen |
| **resetty** | terminal |
| **resize\_term** | screen (locks window list) |
| **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 screen list, 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 (read-only) |
| **strcodes** | global (read-only) |
| **strfnames** | global (read-only) |
| **strnames** | global (read-only) |
| **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 (read-only) |
| **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 screen list, screen) |
| **use\_window** | global (locks window list, 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 window list) |
| **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 |

## RETURN VALUE

**get\_escdelay returns the value of ESCDELAY.** **set\_escdelay and set\_tabsize return ERR upon** **failure and OK upon successful completion.** **use\_screen and use\_window return the** *int* **returned** **by the user-supplied function they are called with.**

## NOTES

*ncurses* **provides both a C function and a preprocessor macro for** **each function documented in this page.**

## PORTABILITY

**These routines are specific to** *ncurses***.** **They were not supported on Version 7, BSD or System V implementations.** **It is recommended that any code depending on** *ncurses* **extensions** **be conditioned using NCURSES\_VERSION.**

## SEE ALSO

**curses(3X),** **curs\_opaque(3X),** **curs\_variables(3X)**
