]> ncurses.scripts.mit.edu Git - ncurses.git/blob - man/curs_threads.3x
7247a52721b6cc5f29826676cf5ae5179c2e9524
[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.46 2023/10/01 09:45:30 tom Exp $
32 .TH curs_threads 3X 2023-10-01 "ncurses 6.4" "Library calls"
33 .ie \n(.g .ds `` \(lq
34 .el       .ds `` ``
35 .ie \n(.g .ds '' \(rq
36 .el       .ds '' ''
37 .de bP
38 .ie n  .IP \(bu 4
39 .el    .IP \(bu 2
40 ..
41 .SH NAME
42 \fI\%NCURSES_WINDOW_CB\fP,
43 \fI\%NCURSES_SCREEN_CB\fP,
44 \fB\%get_escdelay\fP,
45 \fB\%set_escdelay\fP,
46 \fB\%set_tabsize\fP,
47 \fB\%use_screen\fP,
48 \fB\%use_window\fP \-
49 \fIcurses\fR support for multi-threaded applications
50 .SH SYNOPSIS
51 .nf
52 \fB#include <curses.h>\fP
53 .PP
54 \fI/* data types */\fP
55 \fBtypedef int (*NCURSES_WINDOW_CB)(WINDOW *, void *);\fP
56 \fBtypedef int (*NCURSES_SCREEN_CB)(SCREEN *, void *);\fP
57 .PP
58 \fBint get_escdelay(void);\fP
59 \fBint set_escdelay(int \fIms\fB);\fR
60 \fBint set_tabsize(int \fIcols\fB);\fR
61 .PP
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
64 .fi
65 .SH DESCRIPTION
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,
70 for example,
71 since doing so alters \fIncurses\fP's application binary interface
72 (ABI).
73 .PP
74 Instead of modifying the programming interface (API) to make
75 \fIncurses\fP functions expect an additional argument specifying a
76 thread,
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
82 threads of execution.
83 .PP
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
87 \fB\%COLORS\fP,
88 \fB\%COLOR_PAIRS\fP,
89 \fB\%COLS\fP,
90 \fB\%ESCDELAY\fP,
91 \fB\%LINES\fP,
92 \fB\%TABSIZE\fP,
93 \fB\%curscr\fP,
94 \fB\%newscr\fP,
95 and
96 \fB\%ttytype\fP,
97 maintaining them as as read-only values in the \fISCREEN\fP structure.
98 .PP
99 Even this is not enough to make an application using \fIcurses\fP
100 thread-safe.
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).
104 Further,
105 applications expect a few of the global variables to be writable.
106 The functions described here address these special situations.
107 .PP
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.
114 .PP
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 .\" ***************************************************************************
122 .SS Usage
123 All \fIncurses\fP library functions assume that the locale is not
124 altered during operation.
125 In addition,
126 they use data that is maintained within a hierarchy of scopes.
127 .bP
128 global data used in the low-level \fIterminfo\fP or \fItermcap\fP
129 interfaces
130 .bP
131 terminal data associated with a call to \fBset_curterm\fP(3X)
132 .IP
133 Terminal data are initialized when screens are created.
134 .bP
135 screen data associated with a call to \fBnewterm\fP(3X) or
136 \fBinitscr\fP(3X)
137 .bP
138 window data associated with a call to \fBnewwin\fP(3X) or
139 \fBsubwin\fP(3X)
140 .IP
141 Windows are associated with screens.
142 Pads are not necessarily associated with any particular screen.
143 .IP
144 Most \fIcurses\fP applications operate on one or more windows within a
145 single screen.
146 .bP
147 reentrant data associated with \*(``pure\*('' functions that alter no
148 shared variables
149 .PP
150 The following table lists the scope of each symbol in the \fIncurses\fP
151 library when configured to support multi-threaded applications.
152 .PP
153 .TS
154 center tab(/);
155 lb lb
156 lb l .
157 Symbol/Scope
158 =
159 BC/global
160 COLORS/screen (read-only)
161 COLOR_PAIR/reentrant
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
167 PC/global
168 SP/global
169 TABSIZE/screen (read-only; see \fBset_tabsize\fP)
170 UP/global
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)
190 baudrate/screen
191 beep/screen
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
204 cbreak/screen
205 chgat/window (\fBstdscr\fP)
206 clear/window (\fBstdscr\fP)
207 clearok/window
208 clrtobot/window (\fBstdscr\fP)
209 clrtoeol/window (\fBstdscr\fP)
210 color_content/screen
211 color_set/window (\fBstdscr\fP)
212 copywin/window (locks source, target)
213 cur_term/terminal
214 curs_set/screen
215 curscr/screen (read-only)
216 curses_version/global (read-only)
217 def_prog_mode/terminal
218 def_shell_mode/terminal
219 define_key/screen
220 del_curterm/screen
221 delay_output/screen
222 delch/window (\fBstdscr\fP)
223 deleteln/window (\fBstdscr\fP)
224 delscreen/global (locks screen list, screen)
225 delwin/global (locks window list)
226 derwin/screen
227 doupdate/screen
228 dupwin/screen (locks window)
229 echo/screen
230 echo_wchar/window (\fBstdscr\fP)
231 echochar/window (\fBstdscr\fP)
232 endwin/screen
233 erase/window (\fBstdscr\fP)
234 erasechar/window (\fBstdscr\fP)
235 erasewchar/window (\fBstdscr\fP)
236 filter/global
237 flash/terminal
238 flushinp/screen
239 get_wch/screen (input operation)
240 get_wstr/screen (input operation)
241 getattrs/window
242 getbegx/window
243 getbegy/window
244 getbkgd/window
245 getbkgrnd/window
246 getcchar/reentrant
247 getch/screen (input operation)
248 getcurx/window
249 getcury/window
250 getmaxx/window
251 getmaxy/window
252 getmouse/screen (input operation)
253 getn_wstr/screen (input operation)
254 getnstr/screen (input operation)
255 getparx/window
256 getpary/window
257 getstr/screen (input operation)
258 getwin/screen (input operation)
259 halfdelay/screen
260 has_colors/terminal
261 has_ic/terminal
262 has_il/terminal
263 has_key/screen
264 hline/window (\fBstdscr\fP)
265 hline_set/window (\fBstdscr\fP)
266 idcok/window
267 idlok/window
268 immedok/window
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)
275 init_color/screen
276 init_pair/screen
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)
289 intrflush/terminal
290 inwstr/window (\fBstdscr\fP)
291 is_cleared/window
292 is_idcok/window
293 is_idlok/window
294 is_immedok/window
295 is_keypad/window
296 is_leaveok/window
297 is_linetouched/window
298 is_nodelay/window
299 is_notimeout/window
300 is_scrollok/window
301 is_syncok/window
302 is_term_resized/terminal
303 is_wintouched/window
304 isendwin/screen
305 key_defined/screen
306 key_name/global (static data)
307 keybound/screen
308 keyname/global (static data)
309 keyok/screen
310 keypad/window
311 killchar/terminal
312 killwchar/terminal
313 leaveok/window
314 longname/screen
315 mcprint/terminal
316 meta/screen
317 mouse_trafo/window (\fBstdscr\fP)
318 mouseinterval/screen
319 mousemask/screen
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)
332 mvcur/screen
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)
360 mvscanw/screen
361 mvvline/window (\fBstdscr\fP)
362 mvvline_set/window (\fBstdscr\fP)
363 mvwadd_wch/window
364 mvwadd_wchnstr/window
365 mvwadd_wchstr/window
366 mvwaddch/window
367 mvwaddchnstr/window
368 mvwaddchstr/window
369 mvwaddnstr/window
370 mvwaddnwstr/window
371 mvwaddstr/window
372 mvwaddwstr/window
373 mvwchgat/window
374 mvwdelch/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)
381 mvwhline/window
382 mvwhline_set/window
383 mvwin/window
384 mvwin_wch/window
385 mvwin_wchnstr/window
386 mvwin_wchstr/window
387 mvwinch/window
388 mvwinchnstr/window
389 mvwinchstr/window
390 mvwinnstr/window
391 mvwinnwstr/window
392 mvwins_nwstr/window
393 mvwins_wch/window
394 mvwins_wstr/window
395 mvwinsch/window
396 mvwinsnstr/window
397 mvwinsstr/window
398 mvwinstr/window
399 mvwinwstr/window
400 mvwprintw/window
401 mvwscanw/screen
402 mvwvline/window
403 mvwvline_set/window
404 napms/reentrant
405 newpad/global (locks window list)
406 newscr/screen (read-only)
407 newterm/global (locks screen list)
408 newwin/global (locks window list)
409 nl/screen
410 nocbreak/screen
411 nodelay/window
412 noecho/screen
413 nofilter/global
414 nonl/screen
415 noqiflush/terminal
416 noraw/screen
417 notimeout/window
418 numcodes/global (read-only)
419 numfnames/global (read-only)
420 numnames/global (read-only)
421 ospeed/global
422 overlay/window (locks source, target)
423 overwrite/window (locks source, target)
424 pair_content/screen
425 pecho_wchar/screen
426 pechochar/screen
427 pnoutrefresh/screen
428 prefresh/screen
429 printw/window
430 putp/global
431 putwin/window
432 qiflush/terminal
433 raw/screen
434 redrawwin/window
435 refresh/screen
436 reset_prog_mode/screen
437 reset_shell_mode/screen
438 resetty/terminal
439 resize_term/screen (locks window list)
440 resizeterm/screen
441 restartterm/screen
442 ripoffline/global (static data)
443 savetty/terminal
444 scanw/screen
445 scr_dump/screen
446 scr_init/screen
447 scr_restore/screen
448 scr_set/screen
449 scrl/window (\fBstdscr\fP)
450 scroll/window
451 scrollok/window
452 set_curterm/screen
453 set_escdelay/screen
454 set_tabsize/screen
455 set_term/global (locks screen list, screen)
456 setcchar/reentrant
457 setscrreg/window (\fBstdscr\fP)
458 setupterm/global
459 slk_attr/screen
460 slk_attr_off/screen
461 slk_attr_on/screen
462 slk_attr_set/screen
463 slk_attroff/screen
464 slk_attron/screen
465 slk_attrset/screen
466 slk_clear/screen
467 slk_color/screen
468 slk_init/screen
469 slk_label/screen
470 slk_noutrefresh/screen
471 slk_refresh/screen
472 slk_restore/screen
473 slk_set/screen
474 slk_touch/screen
475 slk_wset/screen
476 standend/window
477 standout/window
478 start_color/screen
479 \fBstdscr\fP/screen (read-only)
480 strcodes/global (read-only)
481 strfnames/global (read-only)
482 strnames/global (read-only)
483 subpad/window
484 subwin/window
485 syncok/window
486 term_attrs/screen
487 termattrs/screen
488 termname/terminal
489 tgetent/global
490 tgetflag/global
491 tgetnum/global
492 tgetstr/global
493 tgoto/global
494 tigetflag/terminal
495 tigetnum/terminal
496 tigetstr/terminal
497 timeout/window (\fBstdscr\fP)
498 touchline/window
499 touchwin/window
500 tparm/global (static data)
501 tputs/screen
502 trace/global (static data)
503 ttytype/screen (read-only)
504 typeahead/screen
505 unctrl/screen
506 unget_wch/screen (input operation)
507 ungetch/screen (input operation)
508 ungetmouse/screen (input operation)
509 untouchwin/window
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)
516 vid_attr/screen
517 vid_puts/screen
518 vidattr/screen
519 vidputs/screen
520 vline/window (\fBstdscr\fP)
521 vline_set/window (\fBstdscr\fP)
522 vw_printw/window
523 vw_scanw/screen
524 vwprintw/window
525 vwscanw/screen
526 wadd_wch/window
527 wadd_wchnstr/window
528 wadd_wchstr/window
529 waddch/window
530 waddchnstr/window
531 waddchstr/window
532 waddnstr/window
533 waddnwstr/window
534 waddstr/window
535 waddwstr/window
536 wattr_get/window
537 wattr_off/window
538 wattr_on/window
539 wattr_set/window
540 wattroff/window
541 wattron/window
542 wattrset/window
543 wbkgd/window
544 wbkgdset/window
545 wbkgrnd/window
546 wbkgrndset/window
547 wborder/window
548 wborder_set/window
549 wchgat/window
550 wclear/window
551 wclrtobot/window
552 wclrtoeol/window
553 wcolor_set/window
554 wcursyncup/screen (affects window plus parents)
555 wdelch/window
556 wdeleteln/window
557 wecho_wchar/window
558 wechochar/window
559 wenclose/window
560 werase/window
561 wget_wch/screen (input operation)
562 wget_wstr/screen (input operation)
563 wgetbkgrnd/window
564 wgetch/screen (input operation)
565 wgetdelay/window
566 wgetn_wstr/screen (input operation)
567 wgetnstr/screen (input operation)
568 wgetparent/window
569 wgetscrreg/window
570 wgetstr/screen (input operation)
571 whline/window
572 whline_set/window
573 win_wch/window
574 win_wchnstr/window
575 win_wchstr/window
576 winch/window
577 winchnstr/window
578 winchstr/window
579 winnstr/window
580 winnwstr/window
581 wins_nwstr/window
582 wins_wch/window
583 wins_wstr/window
584 winsch/window
585 winsdelln/window
586 winsertln/window
587 winsnstr/window
588 winsstr/window
589 winstr/window
590 winwstr/window
591 wmouse_trafo/window
592 wmove/window
593 wnoutrefresh/screen
594 wprintw/window
595 wredrawln/window
596 wrefresh/screen
597 wresize/window (locks window list)
598 wscanw/screen
599 wscrl/window
600 wsetscrreg/window
601 wstandend/window
602 wstandout/window
603 wsyncdown/screen (affects window plus parents)
604 wsyncup/screen (affects window plus parents)
605 wtimeout/window
606 wtouchln/window
607 wunctrl/global (static data)
608 wvline/window
609 wvline_set/window
610 .TE
611 .\" ***************************************************************************
612 .SH RETURN VALUE
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.
618 .SH NOTES
619 \fIncurses\fP provides both a C function and a preprocessor macro for
620 each function documented in this page.
621 .SH PORTABILITY
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.
626 .SH SEE ALSO
627 \fB\%curses\fP(3X),
628 \fB\%curs_opaque\fP(3X),
629 \fB\%curs_variables\fP(3X)