简体   繁体   English

Unix C ++第三方API调用

[英]Unix C++ Third party API Call

I am using an API exported from a third party SO file in my C++ application. 我在C ++应用程序中使用从第三方SO文件导出的API。 That third party API is writing some messages to my unix console. 该第三方API正在向我的Unix控制台写入一些消息。 I assume that API uses the concept of multithreading, as I can find the output coming into console is mixed (output from my program as well as out put from this third party API), as below: 我假设API使用了多线程的概念,因为我发现进入控制台的输出是混合的(程序输出以及该第三方API的输出),如下所示:

  • Message from my program: My program 来自我的程序的消息: My program
  • Message from API: I am an API 来自API的消息: I am an API
  • Final output: My I am an program API 最终输出: My I am an program API

Is there there any method by which I can separate both the messages? 有什么方法可以分离这两条消息? Third party SDK document doesn't provide any error/message handling mechanism or any thread synch mechanism. 第三方SDK文档不提供任何错误/消息处理机制或任何线程同步机制。

Can anyone help? 有人可以帮忙吗?

Thread output synchronization and buffering must be done on the level of the application that's outputting it. 线程输出同步和缓冲必须在输出线程的应用程序级别进行。 What you get is already interleaved and can't be reasonably put apart. 您所得到的已经交错,无法合理地分解。 All threads/processes are writing to the same file descriptor (and even worse, they each has its own output buffer, if they are using stdout ), so if that application is not scheduling their output messages, the design is broken and there is very little you can do. 所有线程/进程都写入同一文件描述符(更糟糕的是,如果它们使用stdout ,则每个线程/进程都有其自己的输出缓冲区),因此,如果该应用程序未调度其输出消息,则设计将被破坏,并且存在很多问题。你无能为力。

What kind of application is it? 它是什么类型的应用程序? If it's a shell script wrapper, there's a chance the parallelisation is done on top and can be disassembled and buffered properly. 如果是外壳脚本包装器,则并行化有可能在顶层完成,并且可以适当地反汇编和缓冲。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM