multithreading - 处理来自 ncurses 的用户输入 getch() 比多线程更好?

标签 multithreading ncurses

我正在开发一个游戏,现在我正在使用 getch ncurses 库提供的函数。

来自 here :

The nodelay option causes getch to be a non-blocking call. If no input is ready, getch returns ERR. If disabled (bf is FALSE), getch waits until a key is pressed.



也就是说,默认情况下 getch()是一个阻塞函数,如果你设置了 nodelay为 TRUE 您可以拥有非阻塞输入用户函数。

在另一种方法中,我可以使用多线程来捕获用户输入而不阻塞游戏进程。

问题

我是在浪费时间使用线程重写我的代码,还是可以使用这种方法获得一些东西(速度响应、可移植性等)?

Ncurses 是一个制作控制台应用程序的好库,但我对用户输入有疑问。

最佳答案

如果您有一个多线程应用程序,其中有多个线程在使用显示器,那么它就无法工作 — 不费吹灰之力。

ncurses FAQ 告诉了更多:Why does (fill in the blank) happen when I use two threads?

关于multithreading - 处理来自 ncurses 的用户输入 getch() 比多线程更好?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40589724/

相关文章:

c++ - 对C++多线程真的很困惑

java - 确保缓存自行获取值的线程安全

c - 如何在 C 中使用 setfillstyle() 和 textcolor()

c - Ncurses 和 Linux 管道

调用 calloc - 内存泄漏 valgrind

python - 如何等到信号

java - 在这种情况下是否需要 "volatile"关键字词? ( java )

ios - NSOperationQueue : Trouble understanding the order

当提供从网络接收到的字符串时,Curses printw() 将仅打印换行符

c - mvwprintw 在 for 循环中意外执行