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