2 .\"***************************************************************************
3 .\" Copyright 2021-2022,2023 Thomas E. Dickey *
4 .\" Copyright 2008-2015,2017 Free Software Foundation, Inc. *
6 .\" Permission is hereby granted, free of charge, to any person obtaining a *
7 .\" copy of this software and associated documentation files (the *
8 .\" "Software"), to deal in the Software without restriction, including *
9 .\" without limitation the rights to use, copy, modify, merge, publish, *
10 .\" distribute, distribute with modifications, sublicense, and/or sell *
11 .\" copies of the Software, and to permit persons to whom the Software is *
12 .\" furnished to do so, subject to the following conditions: *
14 .\" The above copyright notice and this permission notice shall be included *
15 .\" in all copies or substantial portions of the Software. *
17 .\" THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS *
18 .\" OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF *
19 .\" MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. *
20 .\" IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, *
21 .\" DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR *
22 .\" OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR *
23 .\" THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
25 .\" Except as contained in this notice, the name(s) of the above copyright *
26 .\" holders shall not be used in advertising or otherwise to promote the *
27 .\" sale, use or other dealings in this Software without prior written *
29 .\"***************************************************************************
31 .\" $Id: curs_threads.3x,v 1.46 2023/10/01 09:45:30 tom Exp $
32 .TH curs_threads 3X 2023-10-01 "ncurses 6.4" "Library calls"
42 \fI\%NCURSES_WINDOW_CB\fP,
43 \fI\%NCURSES_SCREEN_CB\fP,
49 \fIcurses\fR support for multi-threaded applications
52 \fB#include <curses.h>\fP
54 \fI/* data types */\fP
55 \fBtypedef int (*NCURSES_WINDOW_CB)(WINDOW *, void *);\fP
56 \fBtypedef int (*NCURSES_SCREEN_CB)(SCREEN *, void *);\fP
58 \fBint get_escdelay(void);\fP
59 \fBint set_escdelay(int \fIms\fB);\fR
60 \fBint set_tabsize(int \fIcols\fB);\fR
62 \fBint use_screen(SCREEN *\fIscr\fB, NCURSES_SCREEN_CB \fIfunc\fB, void *\fIdata\fB);\fR
63 \fBint use_window(WINDOW *\fIwin\fB, NCURSES_WINDOW_CB \fIfunc\fB, void *\fIdata\fB);\fR
66 The \fIncurses\fP library can be configured to support multi-threaded
67 applications in a rudimentary way.
68 Such configuration produces a different set of libraries,
69 named \fIlibncursest\fP,
71 since doing so alters \fIncurses\fP's application binary interface
74 Instead of modifying the programming interface (API) to make
75 \fIncurses\fP functions expect an additional argument specifying a
77 the library adds a few functions,
78 usable in any configuration,
79 that hide the \fImutexes\fP
80 (mutual exclusion locks)
81 needed to prevent concurrent access to variables shared by multiple
84 \fIncurses\fP threading support requires the use of functions to access
85 members of the \fI\%WINDOW\fP structure (see \fBcurs_opaque\fP(3X)).
86 It further makes functions of the common global variables
97 maintaining them as as read-only values in the \fISCREEN\fP structure.
99 Even this is not enough to make an application using \fIcurses\fP
101 We would expect a multi-threaded application to have threads updating
102 separate windows (on the same device),
103 and separate screens (on different devices).
105 applications expect a few of the global variables to be writable.
106 The functions described here address these special situations.
108 The \fB\%ESCDELAY\fP and \fB\%TABSIZE\fP global variables are modified
109 by some applications.
110 To modify them in any configuration,
111 use the \fB\%set_escdelay\fP or \fB\%set_tabsize\fP functions.
112 Other global variables are not modifiable.
113 \fBget_escdelay\fP retrieves \fB\%ESCDELAY\fP's value.
115 The \fBuse_window\fP and \fBuse_screen\fP functions provide
116 coarse-grained mutexes for their respective \fI\%WINDOW\fP and
117 \fI\%SCREEN\fP parameters;
118 they call a user-supplied function,
119 pass it a \fIdata\fP parameter,
120 and return the value from the user-supplied function to the application.
121 .\" ***************************************************************************
123 All \fIncurses\fP library functions assume that the locale is not
124 altered during operation.
126 they use data that is maintained within a hierarchy of scopes.
128 global data used in the low-level \fIterminfo\fP or \fItermcap\fP
131 terminal data associated with a call to \fBset_curterm\fP(3X)
133 Terminal data are initialized when screens are created.
135 screen data associated with a call to \fBnewterm\fP(3X) or
138 window data associated with a call to \fBnewwin\fP(3X) or
141 Windows are associated with screens.
142 Pads are not necessarily associated with any particular screen.
144 Most \fIcurses\fP applications operate on one or more windows within a
147 reentrant data associated with \*(``pure\*('' functions that alter no
150 The following table lists the scope of each symbol in the \fIncurses\fP
151 library when configured to support multi-threaded applications.
160 COLORS/screen (read-only)
162 COLOR_PAIRS/screen (read-only)
163 COLS/screen (read-only)
164 ESCDELAY/screen (read-only; see \fBset_escdelay\fP)
165 LINES/screen (read-only)
166 PAIR_NUMBER/reentrant
169 TABSIZE/screen (read-only; see \fBset_tabsize\fP)
171 acs_map/screen (read-only)
172 add_wch/window (\fBstdscr\fP)
173 add_wchnstr/window (\fBstdscr\fP)
174 add_wchstr/window (\fBstdscr\fP)
175 addch/window (\fBstdscr\fP)
176 addchnstr/window (\fBstdscr\fP)
177 addchstr/window (\fBstdscr\fP)
178 addnstr/window (\fBstdscr\fP)
179 addnwstr/window (\fBstdscr\fP)
180 addstr/window (\fBstdscr\fP)
181 addwstr/window (\fBstdscr\fP)
182 assume_default_colors/screen
183 attr_get/window (\fBstdscr\fP)
184 attr_off/window (\fBstdscr\fP)
185 attr_on/window (\fBstdscr\fP)
186 attr_set/window (\fBstdscr\fP)
187 attroff/window (\fBstdscr\fP)
188 attron/window (\fBstdscr\fP)
189 attrset/window (\fBstdscr\fP)
192 bkgd/window (\fBstdscr\fP)
193 bkgdset/window (\fBstdscr\fP)
194 bkgrnd/window (\fBstdscr\fP)
195 bkgrndset/window (\fBstdscr\fP)
196 boolcodes/global (read-only)
197 boolfnames/global (read-only)
198 boolnames/global (read-only)
199 border/window (\fBstdscr\fP)
200 border_set/window (\fBstdscr\fP)
201 box/window (\fBstdscr\fP)
202 box_set/window (\fBstdscr\fP)
203 can_change_color/terminal
205 chgat/window (\fBstdscr\fP)
206 clear/window (\fBstdscr\fP)
208 clrtobot/window (\fBstdscr\fP)
209 clrtoeol/window (\fBstdscr\fP)
211 color_set/window (\fBstdscr\fP)
212 copywin/window (locks source, target)
215 curscr/screen (read-only)
216 curses_version/global (read-only)
217 def_prog_mode/terminal
218 def_shell_mode/terminal
222 delch/window (\fBstdscr\fP)
223 deleteln/window (\fBstdscr\fP)
224 delscreen/global (locks screen list, screen)
225 delwin/global (locks window list)
228 dupwin/screen (locks window)
230 echo_wchar/window (\fBstdscr\fP)
231 echochar/window (\fBstdscr\fP)
233 erase/window (\fBstdscr\fP)
234 erasechar/window (\fBstdscr\fP)
235 erasewchar/window (\fBstdscr\fP)
239 get_wch/screen (input operation)
240 get_wstr/screen (input operation)
247 getch/screen (input operation)
252 getmouse/screen (input operation)
253 getn_wstr/screen (input operation)
254 getnstr/screen (input operation)
257 getstr/screen (input operation)
258 getwin/screen (input operation)
264 hline/window (\fBstdscr\fP)
265 hline_set/window (\fBstdscr\fP)
269 in_wch/window (\fBstdscr\fP)
270 in_wchnstr/window (\fBstdscr\fP)
271 in_wchstr/window (\fBstdscr\fP)
272 inch/window (\fBstdscr\fP)
273 inchnstr/window (\fBstdscr\fP)
274 inchstr/window (\fBstdscr\fP)
277 initscr/global (locks screen list)
278 innstr/window (\fBstdscr\fP)
279 innwstr/window (\fBstdscr\fP)
280 ins_nwstr/window (\fBstdscr\fP)
281 ins_wch/window (\fBstdscr\fP)
282 ins_wstr/window (\fBstdscr\fP)
283 insch/window (\fBstdscr\fP)
284 insdelln/window (\fBstdscr\fP)
285 insertln/window (\fBstdscr\fP)
286 insnstr/window (\fBstdscr\fP)
287 insstr/window (\fBstdscr\fP)
288 instr/window (\fBstdscr\fP)
290 inwstr/window (\fBstdscr\fP)
297 is_linetouched/window
302 is_term_resized/terminal
306 key_name/global (static data)
308 keyname/global (static data)
317 mouse_trafo/window (\fBstdscr\fP)
320 move/window (\fBstdscr\fP)
321 mvadd_wch/window (\fBstdscr\fP)
322 mvadd_wchnstr/window (\fBstdscr\fP)
323 mvadd_wchstr/window (\fBstdscr\fP)
324 mvaddch/window (\fBstdscr\fP)
325 mvaddchnstr/window (\fBstdscr\fP)
326 mvaddchstr/window (\fBstdscr\fP)
327 mvaddnstr/window (\fBstdscr\fP)
328 mvaddnwstr/window (\fBstdscr\fP)
329 mvaddstr/window (\fBstdscr\fP)
330 mvaddwstr/window (\fBstdscr\fP)
331 mvchgat/window (\fBstdscr\fP)
333 mvdelch/window (\fBstdscr\fP)
334 mvderwin/window (\fBstdscr\fP)
335 mvget_wch/screen (input operation)
336 mvget_wstr/screen (input operation)
337 mvgetch/screen (input operation)
338 mvgetn_wstr/screen (input operation)
339 mvgetnstr/screen (input operation)
340 mvgetstr/screen (input operation)
341 mvhline/window (\fBstdscr\fP)
342 mvhline_set/window (\fBstdscr\fP)
343 mvin_wch/window (\fBstdscr\fP)
344 mvin_wchnstr/window (\fBstdscr\fP)
345 mvin_wchstr/window (\fBstdscr\fP)
346 mvinch/window (\fBstdscr\fP)
347 mvinchnstr/window (\fBstdscr\fP)
348 mvinchstr/window (\fBstdscr\fP)
349 mvinnstr/window (\fBstdscr\fP)
350 mvinnwstr/window (\fBstdscr\fP)
351 mvins_nwstr/window (\fBstdscr\fP)
352 mvins_wch/window (\fBstdscr\fP)
353 mvins_wstr/window (\fBstdscr\fP)
354 mvinsch/window (\fBstdscr\fP)
355 mvinsnstr/window (\fBstdscr\fP)
356 mvinsstr/window (\fBstdscr\fP)
357 mvinstr/window (\fBstdscr\fP)
358 mvinwstr/window (\fBstdscr\fP)
359 mvprintw/window (\fBstdscr\fP)
361 mvvline/window (\fBstdscr\fP)
362 mvvline_set/window (\fBstdscr\fP)
364 mvwadd_wchnstr/window
375 mvwget_wch/screen (input operation)
376 mvwget_wstr/screen (input operation)
377 mvwgetch/screen (input operation)
378 mvwgetn_wstr/screen (input operation)
379 mvwgetnstr/screen (input operation)
380 mvwgetstr/screen (input operation)
405 newpad/global (locks window list)
406 newscr/screen (read-only)
407 newterm/global (locks screen list)
408 newwin/global (locks window list)
418 numcodes/global (read-only)
419 numfnames/global (read-only)
420 numnames/global (read-only)
422 overlay/window (locks source, target)
423 overwrite/window (locks source, target)
436 reset_prog_mode/screen
437 reset_shell_mode/screen
439 resize_term/screen (locks window list)
442 ripoffline/global (static data)
449 scrl/window (\fBstdscr\fP)
455 set_term/global (locks screen list, screen)
457 setscrreg/window (\fBstdscr\fP)
470 slk_noutrefresh/screen
479 \fBstdscr\fP/screen (read-only)
480 strcodes/global (read-only)
481 strfnames/global (read-only)
482 strnames/global (read-only)
497 timeout/window (\fBstdscr\fP)
500 tparm/global (static data)
502 trace/global (static data)
503 ttytype/screen (read-only)
506 unget_wch/screen (input operation)
507 ungetch/screen (input operation)
508 ungetmouse/screen (input operation)
510 use_default_colors/screen
511 use_env/global (static data)
512 use_extended_names/global (static data)
513 use_legacy_coding/screen
514 use_screen/global (locks screen list, screen)
515 use_window/global (locks window list, window)
520 vline/window (\fBstdscr\fP)
521 vline_set/window (\fBstdscr\fP)
554 wcursyncup/screen (affects window plus parents)
561 wget_wch/screen (input operation)
562 wget_wstr/screen (input operation)
564 wgetch/screen (input operation)
566 wgetn_wstr/screen (input operation)
567 wgetnstr/screen (input operation)
570 wgetstr/screen (input operation)
597 wresize/window (locks window list)
603 wsyncdown/screen (affects window plus parents)
604 wsyncup/screen (affects window plus parents)
607 wunctrl/global (static data)
611 .\" ***************************************************************************
613 \fB\%get_escdelay\fP returns the value of \fB\%ESCDELAY\fP.
614 \fB\%set_escdelay\fP and \fB\%set_tabsize\fP return \fBERR\fP upon
615 failure and \fBOK\fP upon successful completion.
616 \fB\%use_screen\fP and \fB\%use_window\fP return the \fIint\fP returned
617 by the user-supplied function they are called with.
619 \fIncurses\fP provides both a C function and a preprocessor macro for
620 each function documented in this page.
622 These routines are specific to \fIncurses\fP.
623 They were not supported on Version 7, BSD or System V implementations.
624 It is recommended that any code depending on \fIncurses\fP extensions
625 be conditioned using \fB\%NCURSES_VERSION\fP.
628 \fB\%curs_opaque\fP(3X),
629 \fB\%curs_variables\fP(3X)