如何使用线程同时下载和转换二进制文件? [英] How do I concurrently download and convert a binary file using threads?

查看:124
本文介绍了如何使用线程同时下载和转换二进制文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个程序从另一台电脑下载一个二进制文件。

我还有另一个独立程序,可以将此二进制文件转换为人类可读的CSV。

I have a program that downloads a binary file, from another PC.
I also have a another standalone program that can convert this binary file to a human readable CSV.

我想将转换工具带入下载工具,在下载工具中创建一个线程,启动转换代码(因此可以开始转换它正在下载,减少下载和转换的总时间独立)。

I would like to bring the conversion tool "into" the download tool, creating a thread in the download tool that kicks off the conversion code (so it can start converting while it is downloading, reducing the total time of download and convert independently).

我相信我可以成功地启动另一个线程,但如何同步转换线程与主下载?

I believe I can successfully kick off another thread but how do I synchronize the conversion thread with the main download?

这类似于同步执行多个主题?如果是这样,这意味着下载的二进制文件需要由信号量访问的资源?

Is this similar to the Synchronizing Execution of Multiple Threads ? If so does this mean the downloaded binary needs to be a resource accessed by semaphores?

我在正确的路径上,或者在开始之前应该指向另一个方向吗?

Am I on the right path or should i be pointed in another direction before I start?

感谢任何建议。

谢谢。

推荐答案

这是生产者 - 消费者的经典案例问题下载线程作为生成器转换线程作为消费者

Google,您会找到您选择的语言的实施。以下是来自MSDN的一些信息:如何:实施各种生产者 - 消费者模式

Google around and you'll find an implementation for your language of choice. Here are some from MSDN: How to: Implement Various Producer-Consumer Patterns.

这篇关于如何使用线程同时下载和转换二进制文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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