使输出流线程安全. [英] Making output streams thread safe..

查看:78
本文介绍了使输出流线程安全.的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个使用WriteFile()直接写入控制台的应用程序(我的),但我还必须与另一个应用程序共享该控制台(据我所知,它写入stdout).有人知道我可以强制输出同步的方法吗?这样就不会出现输出重叠/损坏的情况.我的应用程序使用控制台锁来防止这种情况发生-但是我无法控制第三方应用程序.

问候.
James

I have an application (mine) that uses WriteFile() to write directly to the console, but I also have to share that console with another application that (as far as I know writes to stdout). Does anybody know of a way that I can force synchronisation of the output - so that there is no output overlap/corruption. My application uses a console lock to prevent this happening - but I have no control over a third-party app.

Regards.
James

推荐答案

如果您无法控制其他应用程序,我能想到的唯一解决方案是将其他应用程序的输出重定向到您的应用程序,然后对您的应用程序进行编码,以在适当的时候编写其他应用程序的输出.

您可能需要扫描其他应用程序的输出,以确定如何拆分数据(例如,累积整行或查找一些已知模式).

您可能还会有一些超时,因此,如果另一个应用程序在一个时间范围内不打印整行,您将输出所拥有的内容.
The only solution I can think of if you don''t have control over other applications would be to redirect the output of other application to your application and then code your application to write the output of other application at appropriate time.

You might want to scan the output of other applications to decide how to split the data (for example to accumulate complete line or find some known patterns).

You might also have some timeout so that if the other application do not print a whole line in a time frame, you would output what you have.


问题是-我不启动第三方应用.我无法控制它-重定向输出不是一种选择.有谁知道写stdout/err时设置的内部锁.我知道新版本的C ++(0x)包括线程安全意识-但是任何提示都将不胜感激.

詹姆斯.
The thing is - I do not launch the third-party app. I have no control over it what-so-ever - so redirected output is not an option. Does anyone know of an internal lock that gets set when writing to stdout/err. I know the new version of C++ (0x) includes thread-safe awareness - but any tip would be appreciated.

James.


这篇关于使输出流线程安全.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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