]> ncurses.scripts.mit.edu Git - ncurses.git/blob - man/curs_threads.3x
ncurses 6.4 - patch 20231125
[ncurses.git] / man / curs_threads.3x
1 '\" t
2 .\"***************************************************************************
3 .\" Copyright 2021-2022,2023 Thomas E. Dickey                                *
4 .\" Copyright 2008-2015,2017 Free Software Foundation, Inc.                  *
5 .\"                                                                          *
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:                 *
13 .\"                                                                          *
14 .\" The above copyright notice and this permission notice shall be included  *
15 .\" in all copies or substantial portions of the Software.                   *
16 .\"                                                                          *
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.                               *
24 .\"                                                                          *
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       *
28 .\" authorization.                                                           *
29 .\"***************************************************************************
30 .\"
31 .\" $Id: curs_threads.3x,v 1.49 2023/11/25 14:09:12 tom Exp $
32 .TH curs_threads 3X 2023-11-25 "ncurses 6.4" "Library calls"
33 .ie \n(.g \{\
34 .ds `` \(lq
35 .ds '' \(rq
36 .\}
37 .el \{\
38 .ie t .ds `` ``
39 .el   .ds `` ""
40 .ie t .ds '' ''
41 .el   .ds '' ""
42 .\}
43 .
44 .de bP
45 .ie n  .IP \(bu 4
46 .el    .IP \(bu 2
47 ..
48 .SH NAME
49 \fI\%NCURSES_WINDOW_CB\fP,
50 \fI\%NCURSES_SCREEN_CB\fP,
51 \fB\%get_escdelay\fP,
52 \fB\%set_escdelay\fP,
53 \fB\%set_tabsize\fP,
54 \fB\%use_screen\fP,
55 \fB\%use_window\fP \-
56 \fIcurses\fR support for multi-threaded applications
57 .SH SYNOPSIS
58 .nf
59 \fB#include <curses.h>
60 .PP
61 \fI/* data types */
62 \fBtypedef int (*NCURSES_WINDOW_CB)(WINDOW *, void *);
63 \fBtypedef int (*NCURSES_SCREEN_CB)(SCREEN *, void *);
64 .PP
65 \fBint get_escdelay(void);
66 \fBint set_escdelay(int \fIms\fP);
67 \fBint set_tabsize(int \fIcols\fP);
68 .PP
69 \fBint use_screen(SCREEN *\fIscr\fP, NCURSES_SCREEN_CB \fIfunc\fP, void *\fIdata\fP);
70 \fBint use_window(WINDOW *\fIwin\fP, NCURSES_WINDOW_CB \fIfunc\fP, void *\fIdata\fP);
71 .fi
72 .SH DESCRIPTION
73 The \fIncurses\fP library can be configured to support multi-threaded
74 applications in a rudimentary way.
75 Such configuration produces a different set of libraries,
76 named \fIlibncursest\fP,
77 for example,
78 since doing so alters \fIncurses\fP's application binary interface
79 (ABI).
80 .PP
81 Instead of modifying the programming interface (API) to make
82 \fIncurses\fP functions expect an additional argument specifying a
83 thread,
84 the library adds functions,
85 usable in any configuration,
86 that hide the \fImutexes\fP
87 (mutual exclusion locks)
88 needed to prevent concurrent access to variables shared by multiple
89 threads of execution.
90 .PP
91 \fIncurses\fP threading support requires the use of functions to access
92 members of the \fI\%WINDOW\fP structure (see \fBcurs_opaque\fP(3X)).
93 It further makes functions of the common global variables
94 \fB\%COLORS\fP,
95 \fB\%COLOR_PAIRS\fP,
96 \fB\%COLS\fP,
97 \fB\%ESCDELAY\fP,
98 \fB\%LINES\fP,
99 \fB\%TABSIZE\fP,
100 \fB\%curscr\fP,
101 \fB\%newscr\fP,
102 and
103 \fB\%ttytype\fP,
104 maintaining them as as read-only values in the \fISCREEN\fP structure.
105 .PP
106 Even this is not enough to make an application using \fIcurses\fP
107 thread-safe.
108 We would expect a multi-threaded application to have threads updating
109 separate windows (on the same device),
110 and separate screens (on different devices).
111 Further,
112 applications expect a few of the global variables to be writable.
113 The functions described here address these special situations.
114 .PP
115 The \fB\%ESCDELAY\fP and \fB\%TABSIZE\fP global variables are modified
116 by some applications.
117 To modify them in any configuration,
118 use the \fB\%set_escdelay\fP or \fB\%set_tabsize\fP functions.
119 Other global variables are not modifiable.
120 \fBget_escdelay\fP retrieves \fB\%ESCDELAY\fP's value.
121 .PP
122 The \fBuse_window\fP and \fBuse_screen\fP functions provide
123 coarse-grained mutexes for their respective \fI\%WINDOW\fP and
124 \fI\%SCREEN\fP parameters;
125 they call a user-supplied function,
126 pass it a \fIdata\fP parameter,
127 and return the value from the user-supplied function to the application.
128 .\" ***************************************************************************
129 .SS Usage
130 All \fIncurses\fP library functions assume that the locale is not
131 altered during operation.
132 In addition,
133 they use data that is maintained within a hierarchy of scopes.
134 .bP
135 global data used in the low-level \fIterminfo\fP or \fItermcap\fP
136 interfaces
137 .bP
138 terminal data associated with a call to \fBset_curterm\fP(3X)
139 .IP
140 Terminal data are initialized when screens are created.
141 .bP
142 screen data associated with a call to \fBnewterm\fP(3X) or
143 \fBinitscr\fP(3X)
144 .bP
145 window data associated with a call to \fBnewwin\fP(3X) or
146 \fBsubwin\fP(3X)
147 .IP
148 Windows are associated with screens.
149 Pads are not necessarily associated with any particular screen.
150 .IP
151 Most \fIcurses\fP applications operate on one or more windows within a
152 single screen.
153 .bP
154 reentrant data associated with \*(``pure\*('' functions that alter no
155 shared variables
156 .PP
157 The following table lists the scope of each symbol in the \fIncurses\fP
158 library when configured to support multi-threaded applications.
159 .PP
160 .TS
161 center tab(/);
162 lb lb
163 lb l .
164 Symbol/Scope
165 =
166 BC/global
167 COLORS/screen (read-only)
168 COLOR_PAIR/reentrant
169 COLOR_PAIRS/screen (read-only)
170 COLS/screen (read-only)
171 ESCDELAY/screen (read-only; see \fBset_escdelay\fP)
172 LINES/screen (read-only)
173 PAIR_NUMBER/reentrant
174 PC/global
175 SP/global
176 TABSIZE/screen (read-only; see \fBset_tabsize\fP)
177 UP/global
178 acs_map/screen (read-only)
179 add_wch/window (\fBstdscr\fP)
180 add_wchnstr/window (\fBstdscr\fP)
181 add_wchstr/window (\fBstdscr\fP)
182 addch/window (\fBstdscr\fP)
183 addchnstr/window (\fBstdscr\fP)
184 addchstr/window (\fBstdscr\fP)
185 addnstr/window (\fBstdscr\fP)
186 addnwstr/window (\fBstdscr\fP)
187 addstr/window (\fBstdscr\fP)
188 addwstr/window (\fBstdscr\fP)
189 assume_default_colors/screen
190 attr_get/window (\fBstdscr\fP)
191 attr_off/window (\fBstdscr\fP)
192 attr_on/window (\fBstdscr\fP)
193 attr_set/window (\fBstdscr\fP)
194 attroff/window (\fBstdscr\fP)
195 attron/window (\fBstdscr\fP)
196 attrset/window (\fBstdscr\fP)
197 baudrate/screen
198 beep/screen
199 bkgd/window (\fBstdscr\fP)
200 bkgdset/window (\fBstdscr\fP)
201 bkgrnd/window (\fBstdscr\fP)
202 bkgrndset/window (\fBstdscr\fP)
203 boolcodes/global (read-only)
204 boolfnames/global (read-only)
205 boolnames/global (read-only)
206 border/window (\fBstdscr\fP)
207 border_set/window (\fBstdscr\fP)
208 box/window (\fBstdscr\fP)
209 box_set/window (\fBstdscr\fP)
210 can_change_color/terminal
211 cbreak/screen
212 chgat/window (\fBstdscr\fP)
213 clear/window (\fBstdscr\fP)
214 clearok/window
215 clrtobot/window (\fBstdscr\fP)
216 clrtoeol/window (\fBstdscr\fP)
217 color_content/screen
218 color_set/window (\fBstdscr\fP)
219 copywin/window (locks source, target)
220 cur_term/terminal
221 curs_set/screen
222 curscr/screen (read-only)
223 curses_version/global (read-only)
224 def_prog_mode/terminal
225 def_shell_mode/terminal
226 define_key/screen
227 del_curterm/screen
228 delay_output/screen
229 delch/window (\fBstdscr\fP)
230 deleteln/window (\fBstdscr\fP)
231 delscreen/global (locks screen list, screen)
232 delwin/global (locks window list)
233 derwin/screen
234 doupdate/screen
235 dupwin/screen (locks window)
236 echo/screen
237 echo_wchar/window (\fBstdscr\fP)
238 echochar/window (\fBstdscr\fP)
239 endwin/screen
240 erase/window (\fBstdscr\fP)
241 erasechar/window (\fBstdscr\fP)
242 erasewchar/window (\fBstdscr\fP)
243 filter/global
244 flash/terminal
245 flushinp/screen
246 get_wch/screen (input operation)
247 get_wstr/screen (input operation)
248 getattrs/window
249 getbegx/window
250 getbegy/window
251 getbkgd/window
252 getbkgrnd/window
253 getcchar/reentrant
254 getch/screen (input operation)
255 getcurx/window
256 getcury/window
257 getmaxx/window
258 getmaxy/window
259 getmouse/screen (input operation)
260 getn_wstr/screen (input operation)
261 getnstr/screen (input operation)
262 getparx/window
263 getpary/window
264 getstr/screen (input operation)
265 getwin/screen (input operation)
266 halfdelay/screen
267 has_colors/terminal
268 has_ic/terminal
269 has_il/terminal
270 has_key/screen
271 hline/window (\fBstdscr\fP)
272 hline_set/window (\fBstdscr\fP)
273 idcok/window
274 idlok/window
275 immedok/window
276 in_wch/window (\fBstdscr\fP)
277 in_wchnstr/window (\fBstdscr\fP)
278 in_wchstr/window (\fBstdscr\fP)
279 inch/window (\fBstdscr\fP)
280 inchnstr/window (\fBstdscr\fP)
281 inchstr/window (\fBstdscr\fP)
282 init_color/screen
283 init_pair/screen
284 initscr/global (locks screen list)
285 innstr/window (\fBstdscr\fP)
286 innwstr/window (\fBstdscr\fP)
287 ins_nwstr/window (\fBstdscr\fP)
288 ins_wch/window (\fBstdscr\fP)
289 ins_wstr/window (\fBstdscr\fP)
290 insch/window (\fBstdscr\fP)
291 insdelln/window (\fBstdscr\fP)
292 insertln/window (\fBstdscr\fP)
293 insnstr/window (\fBstdscr\fP)
294 insstr/window (\fBstdscr\fP)
295 instr/window (\fBstdscr\fP)
296 intrflush/terminal
297 inwstr/window (\fBstdscr\fP)
298 is_cleared/window
299 is_idcok/window
300 is_idlok/window
301 is_immedok/window
302 is_keypad/window
303 is_leaveok/window
304 is_linetouched/window
305 is_nodelay/window
306 is_notimeout/window
307 is_scrollok/window
308 is_syncok/window
309 is_term_resized/terminal
310 is_wintouched/window
311 isendwin/screen
312 key_defined/screen
313 key_name/global (static data)
314 keybound/screen
315 keyname/global (static data)
316 keyok/screen
317 keypad/window
318 killchar/terminal
319 killwchar/terminal
320 leaveok/window
321 longname/screen
322 mcprint/terminal
323 meta/screen
324 mouse_trafo/window (\fBstdscr\fP)
325 mouseinterval/screen
326 mousemask/screen
327 move/window (\fBstdscr\fP)
328 mvadd_wch/window (\fBstdscr\fP)
329 mvadd_wchnstr/window (\fBstdscr\fP)
330 mvadd_wchstr/window (\fBstdscr\fP)
331 mvaddch/window (\fBstdscr\fP)
332 mvaddchnstr/window (\fBstdscr\fP)
333 mvaddchstr/window (\fBstdscr\fP)
334 mvaddnstr/window (\fBstdscr\fP)
335 mvaddnwstr/window (\fBstdscr\fP)
336 mvaddstr/window (\fBstdscr\fP)
337 mvaddwstr/window (\fBstdscr\fP)
338 mvchgat/window (\fBstdscr\fP)
339 mvcur/screen
340 mvdelch/window (\fBstdscr\fP)
341 mvderwin/window (\fBstdscr\fP)
342 mvget_wch/screen (input operation)
343 mvget_wstr/screen (input operation)
344 mvgetch/screen (input operation)
345 mvgetn_wstr/screen (input operation)
346 mvgetnstr/screen (input operation)
347 mvgetstr/screen (input operation)
348 mvhline/window (\fBstdscr\fP)
349 mvhline_set/window (\fBstdscr\fP)
350 mvin_wch/window (\fBstdscr\fP)
351 mvin_wchnstr/window (\fBstdscr\fP)
352 mvin_wchstr/window (\fBstdscr\fP)
353 mvinch/window (\fBstdscr\fP)
354 mvinchnstr/window (\fBstdscr\fP)
355 mvinchstr/window (\fBstdscr\fP)
356 mvinnstr/window (\fBstdscr\fP)
357 mvinnwstr/window (\fBstdscr\fP)
358 mvins_nwstr/window (\fBstdscr\fP)
359 mvins_wch/window (\fBstdscr\fP)
360 mvins_wstr/window (\fBstdscr\fP)
361 mvinsch/window (\fBstdscr\fP)
362 mvinsnstr/window (\fBstdscr\fP)
363 mvinsstr/window (\fBstdscr\fP)
364 mvinstr/window (\fBstdscr\fP)
365 mvinwstr/window (\fBstdscr\fP)
366 mvprintw/window (\fBstdscr\fP)
367 mvscanw/screen
368 mvvline/window (\fBstdscr\fP)
369 mvvline_set/window (\fBstdscr\fP)
370 mvwadd_wch/window
371 mvwadd_wchnstr/window
372 mvwadd_wchstr/window
373 mvwaddch/window
374 mvwaddchnstr/window
375 mvwaddchstr/window
376 mvwaddnstr/window
377 mvwaddnwstr/window
378 mvwaddstr/window
379 mvwaddwstr/window
380 mvwchgat/window
381 mvwdelch/window
382 mvwget_wch/screen (input operation)
383 mvwget_wstr/screen (input operation)
384 mvwgetch/screen (input operation)
385 mvwgetn_wstr/screen (input operation)
386 mvwgetnstr/screen (input operation)
387 mvwgetstr/screen (input operation)
388 mvwhline/window
389 mvwhline_set/window
390 mvwin/window
391 mvwin_wch/window
392 mvwin_wchnstr/window
393 mvwin_wchstr/window
394 mvwinch/window
395 mvwinchnstr/window
396 mvwinchstr/window
397 mvwinnstr/window
398 mvwinnwstr/window
399 mvwins_nwstr/window
400 mvwins_wch/window
401 mvwins_wstr/window
402 mvwinsch/window
403 mvwinsnstr/window
404 mvwinsstr/window
405 mvwinstr/window
406 mvwinwstr/window
407 mvwprintw/window
408 mvwscanw/screen
409 mvwvline/window
410 mvwvline_set/window
411 napms/reentrant
412 newpad/global (locks window list)
413 newscr/screen (read-only)
414 newterm/global (locks screen list)
415 newwin/global (locks window list)
416 nl/screen
417 nocbreak/screen
418 nodelay/window
419 noecho/screen
420 nofilter/global
421 nonl/screen
422 noqiflush/terminal
423 noraw/screen
424 notimeout/window
425 numcodes/global (read-only)
426 numfnames/global (read-only)
427 numnames/global (read-only)
428 ospeed/global
429 overlay/window (locks source, target)
430 overwrite/window (locks source, target)
431 pair_content/screen
432 pecho_wchar/screen
433 pechochar/screen
434 pnoutrefresh/screen
435 prefresh/screen
436 printw/window
437 putp/global
438 putwin/window
439 qiflush/terminal
440 raw/screen
441 redrawwin/window
442 refresh/screen
443 reset_prog_mode/screen
444 reset_shell_mode/screen
445 resetty/terminal
446 resize_term/screen (locks window list)
447 resizeterm/screen
448 restartterm/screen
449 ripoffline/global (static data)
450 savetty/terminal
451 scanw/screen
452 scr_dump/screen
453 scr_init/screen
454 scr_restore/screen
455 scr_set/screen
456 scrl/window (\fBstdscr\fP)
457 scroll/window
458 scrollok/window
459 set_curterm/screen
460 set_escdelay/screen
461 set_tabsize/screen
462 set_term/global (locks screen list, screen)
463 setcchar/reentrant
464 setscrreg/window (\fBstdscr\fP)
465 setupterm/global
466 slk_attr/screen
467 slk_attr_off/screen
468 slk_attr_on/screen
469 slk_attr_set/screen
470 slk_attroff/screen
471 slk_attron/screen
472 slk_attrset/screen
473 slk_clear/screen
474 slk_color/screen
475 slk_init/screen
476 slk_label/screen
477 slk_noutrefresh/screen
478 slk_refresh/screen
479 slk_restore/screen
480 slk_set/screen
481 slk_touch/screen
482 slk_wset/screen
483 standend/window
484 standout/window
485 start_color/screen
486 \fBstdscr\fP/screen (read-only)
487 strcodes/global (read-only)
488 strfnames/global (read-only)
489 strnames/global (read-only)
490 subpad/window
491 subwin/window
492 syncok/window
493 term_attrs/screen
494 termattrs/screen
495 termname/terminal
496 tgetent/global
497 tgetflag/global
498 tgetnum/global
499 tgetstr/global
500 tgoto/global
501 tigetflag/terminal
502 tigetnum/terminal
503 tigetstr/terminal
504 timeout/window (\fBstdscr\fP)
505 touchline/window
506 touchwin/window
507 tparm/global (static data)
508 tputs/screen
509 trace/global (static data)
510 ttytype/screen (read-only)
511 typeahead/screen
512 unctrl/screen
513 unget_wch/screen (input operation)
514 ungetch/screen (input operation)
515 ungetmouse/screen (input operation)
516 untouchwin/window
517 use_default_colors/screen
518 use_env/global (static data)
519 use_extended_names/global (static data)
520 use_legacy_coding/screen
521 use_screen/global (locks screen list, screen)
522 use_window/global (locks window list, window)
523 vid_attr/screen
524 vid_puts/screen
525 vidattr/screen
526 vidputs/screen
527 vline/window (\fBstdscr\fP)
528 vline_set/window (\fBstdscr\fP)
529 vw_printw/window
530 vw_scanw/screen
531 vwprintw/window
532 vwscanw/screen
533 wadd_wch/window
534 wadd_wchnstr/window
535 wadd_wchstr/window
536 waddch/window
537 waddchnstr/window
538 waddchstr/window
539 waddnstr/window
540 waddnwstr/window
541 waddstr/window
542 waddwstr/window
543 wattr_get/window
544 wattr_off/window
545 wattr_on/window
546 wattr_set/window
547 wattroff/window
548 wattron/window
549 wattrset/window
550 wbkgd/window
551 wbkgdset/window
552 wbkgrnd/window
553 wbkgrndset/window
554 wborder/window
555 wborder_set/window
556 wchgat/window
557 wclear/window
558 wclrtobot/window
559 wclrtoeol/window
560 wcolor_set/window
561 wcursyncup/screen (affects window plus parents)
562 wdelch/window
563 wdeleteln/window
564 wecho_wchar/window
565 wechochar/window
566 wenclose/window
567 werase/window
568 wget_wch/screen (input operation)
569 wget_wstr/screen (input operation)
570 wgetbkgrnd/window
571 wgetch/screen (input operation)
572 wgetdelay/window
573 wgetn_wstr/screen (input operation)
574 wgetnstr/screen (input operation)
575 wgetparent/window
576 wgetscrreg/window
577 wgetstr/screen (input operation)
578 whline/window
579 whline_set/window
580 win_wch/window
581 win_wchnstr/window
582 win_wchstr/window
583 winch/window
584 winchnstr/window
585 winchstr/window
586 winnstr/window
587 winnwstr/window
588 wins_nwstr/window
589 wins_wch/window
590 wins_wstr/window
591 winsch/window
592 winsdelln/window
593 winsertln/window
594 winsnstr/window
595 winsstr/window
596 winstr/window
597 winwstr/window
598 wmouse_trafo/window
599 wmove/window
600 wnoutrefresh/screen
601 wprintw/window
602 wredrawln/window
603 wrefresh/screen
604 wresize/window (locks window list)
605 wscanw/screen
606 wscrl/window
607 wsetscrreg/window
608 wstandend/window
609 wstandout/window
610 wsyncdown/screen (affects window plus parents)
611 wsyncup/screen (affects window plus parents)
612 wtimeout/window
613 wtouchln/window
614 wunctrl/global (static data)
615 wvline/window
616 wvline_set/window
617 .TE
618 .\" ***************************************************************************
619 .SH RETURN VALUE
620 \fB\%get_escdelay\fP returns the value of \fB\%ESCDELAY\fP.
621 \fB\%set_escdelay\fP and \fB\%set_tabsize\fP return \fBERR\fP upon
622 failure and \fBOK\fP upon successful completion.
623 \fB\%use_screen\fP and \fB\%use_window\fP return the \fIint\fP returned
624 by the user-supplied function they are called with.
625 .SH NOTES
626 \fIncurses\fP provides both a C function and a preprocessor macro for
627 each function documented in this page.
628 .SH PORTABILITY
629 These routines are specific to \fIncurses\fP.
630 They were not supported on Version 7, BSD or System V implementations.
631 It is recommended that any code depending on \fIncurses\fP extensions
632 be conditioned using \fB\%NCURSES_VERSION\fP.
633 .SH SEE ALSO
634 \fB\%curses\fP(3X),
635 \fB\%curs_opaque\fP(3X),
636 \fB\%curs_variables\fP(3X)