强制退出readline()函数 [英] force exit from readline() function

查看:75
本文介绍了强制退出readline()函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在用C ++编写程序,该程序在单独的线程中运行GNU readline.当退出主线程时,我需要完成调用readline()函数的线程.仅当标准输入出现(按下)时,才返回readline()函数.有什么方法可以将输入发送到应用程序或从readline函数显式返回?预先感谢.

I am writing program in c++ which runs GNU readline in separate thread. When main thread is exited I need to finish the thread in which readline() function is called. The readline() function is returned only when standart input came (enter pressed). Is there any way to send input to application or explicitly return from readline function? Thanks in advance.

推荐答案

而不是从主线程返回,而是调用exit(errno).所有其他线程将被讨厌地杀死!

Instead of returning from main thread, call exit(errno). All other threads will be killed nastily!

或者,如果您想变得更好,并且取决于您的操作系统,可以向readline线程发送信号,这会中断syscall.

Or, if you wanted to be nicer, and depending on your OS, you could send a signal to the readline thread, which would interrupt the syscall.

或者,如果您想变得更聪明,可以运行 readline,在异步模式下,使用带有超时的select()循环,这样您的线程就不会阻塞readine函数,并且线程可以在其自身之后进行清理.

Or, if you wanted to be cleverer, you could run readline in async mode, using a select() loop with a timeout so that your thread never blocks in readine functions, and your thread can clean up after itself.

这篇关于强制退出readline()函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆