多线程-使用第二线程编写 [英] Multithreading-- Writing using 2nd thread

查看:137
本文介绍了多线程-使用第二线程编写的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在基于对话框的应用程序中,我有2个线程,一个用于从file1读取一个块,另一个用于将从file1读取的块写入file2.
用于* fp的fopen()和用于读取和写入InitDialog()中定义的文件的* fpout. 第二个线程没有写任何东西,而是像在InitDialog()中那样创建了文件.但是如果在file2中fopen * fpout for file2在线程2中正在写???
是否需要一次又一次打开文件ptr进行线程写????

In a dialog based application,I m having 2 threads one for reading a block from file1 and another for writing the block read from file1 into file2.
The fopen()for *fp and *fpout for reading and writing file respectively defined in InitDialog().
The 2nd thread is not writing anything but file is created as it is in InitDialog().But if fopen *fpout for the file2 is in thread2 it is writing???
Is the file ptr needs to open again and again for thread writing????

推荐答案

skskskskskskskss写道:
sksksksksksksks wrote:

用于* fp的fopen()和用于读取的* fpout

The fopen()for *fp and *fpout for reading



我以为您说您使用的是C ++,而不是C?



I thought you said you were using C++, not C ?


如果您有一个线程可以读取输入文件,而另一个线程可以写入输出文件,在我看来让负责处理文件的线程成为负责打开和关闭该文件的线程是很有意义的.

由于您是在线程之间拆分输出文件的处理,因此在我看来似乎有2个明显的潜在问题点.

1)来自第一个线程的有效FILE *是否正确地传递给第二个线程?

2)关于处理两个线程之间的输出文件是否存在任何同步问题?
If you have one thread for reading from an input file and a second thread for writing to an output file, it seems to me that having the thread that handles the file be the one that is responsible for opening and closing it makes sense.

Since you are splitting the handling of the output file between the threads, it seems to me that there are 2 obvious potential trouble spots.

1) Is the valid FILE * from the 1st thread being correctly communicated to the second thread?

2) Are there any synchronization problems concerning handling the output file between the two threads?


这篇关于多线程-使用第二线程编写的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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