Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
607 views
in Technique[技术] by (71.8m points)

thread safety - Why has no one written a threadsafe branch of the ncurses library?

NCurses appears to be a popular library. One of its weaknesses is, that it is not threadsafe. It should not be hard to wrap shared ressources in mutexes.

Is there a specific reason, why noone has started a threadsafe branch? (Legal issues, introducing a platform dependency, ...)

Edit: I do not mean the use_screen or use_window functions. These apparently require the user to change his NCurses-based code. It should be possible to add a mutex to the shared resources within the NCurses itself, and all accessing functions acquire the mutex before doing something with the window. I am imagining something like this within NCurses:

#if __cplusplus >= 201103L
#include <mutex>
#define THREADSAFE
#endif
...
#ifdef THREADSAFE
std::recursive_mutex  mxCurscr;
#endif
...
int doupdate(void)
{
#ifdef THREADSAFE
mxCurscr.lock();
#endif
... // <-- Access the screen here.
#ifdef THREADSAFE
mxCurscr.unlock()
#endif
}
  • This does not rely on anything but the C++11 standard.
  • This is compatible with older compilers. (But no threadsafety then.)
  • It should not take more than one or two days to make the modifications.
  • This satisfies the demand for a threadsafe NCurses.
  • The user of the NCurses library will not have to bother.
  • The work is being done one time for all users, instead of having every user implementing its own thread-safety.

So, where is the catch?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

It's already been done (in ncurses 5.7, released November 2008), but not much used. See the curs_threads manual page for instance. It is not a feature in the default configuration because it

  • changes the ABI (application binary interface), and
  • adds some restrictions on how standard variables are used.

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...