可以从多个线程写入文件? [英] Writing to a file from more than one thread possible?

查看:73
本文介绍了可以从多个线程写入文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要能够从大约4

不同的线程同时写入文件。我正在开发一个程序,它将下载部分

文件并组合这些部分。每个线程都有一个零偏移量和一个

长度来写。没有任何线程会在文件位置重叠。


是否可以让多个线程打开(共享)文件?我是b / b
猜测我会使用某种文件流进行某种共享。寻找

一些指针和/或示例。谢谢!

I need to be able to write to a file simultaneously from approximately 4
different threads. I''m working on a program that will download parts of a
file and combine the parts. Each thread will have an offset from zero and a
length to write. None of the threads will overlap in the file position.

Is it possible to have the file open (shared) by multiple threads? I''m
guessing that i''d use a filestream with some sort of sharing. Looking for
some pointers and/or examples. Thanks!

推荐答案

我需要能够从大约
I need to be able to write to a file simultaneously from approximately
$ b同时写入文件$ b 4个不同的主题。我正在开发一个程序,它将下载文件的部分

并组合这些部分。每个线程都有一个偏离

零和写入的长度。没有任何线程会在

文件位置重叠。


是否可以让多个线程打开(共享)文件?我是b / b
猜测我会使用某种文件流进行某种共享。查看

的一些指针和/或示例。谢谢!
4 different threads. I''m working on a program that will download parts
of a file and combine the parts. Each thread will have an offset from
zero and a length to write. None of the threads will overlap in the
file position.

Is it possible to have the file open (shared) by multiple threads? I''m
guessing that i''d use a filestream with some sort of sharing. Looking
for some pointers and/or examples. Thanks!



让多个线程写入不同的

文件并在最后通过创建它们将它们组合起来并不简单此时的最终文件,

按顺序从这些其他文件中绘制出来的数据?


-

Rory

Wouldn''t it just be simpler to have the multiple threads write to different
files and combine them at the end by creating the final file at this point,
drawing it''s data from these other file in sequence?

--
Rory


>
>

让多个线程写入

不同的文件并在最后通过创建

这一点的最终文件,按顺序从这些其他文件中抽取它的数据?
Wouldn''t it just be simpler to have the multiple threads write to
different files and combine them at the end by creating the final file at
this point, drawing it''s data from these other file in sequence?



不,我正在使用一个程序现在可以做到这一点,它创建了数千个小b $ b小文件,然后在完成后将它们组合在一起。这导致不断的

硬盘驱动器活动,并且我的计算机在程序执行时无法使用

。所以我试图复制程序并将数据合并在

上,只在硬盘上写一个文件。


我'一直倾向于拥有一个文件管理器。我传递一个字节的线程

array&文件偏移并让它进行写作。

No, I''m using a program that does that right now and it creates thousands of
small files and then combines them when it''s all done. This causes constant
hard drive activity and my computer is unusable while the program is doing
this. So i''m trying to duplicate the program and combine the data on the
fly, only writing the one file on the hard drive.

I''ve been leaning toward having one "file manager" thread that I pass a byte
array & file offset and let it do the writing.


我只是好奇为什么你选择了四个线程。我的意思是,如果你想要一些最优的东西,我认为线程数是基于缓冲区大小的。在

理论中,我怀疑这个问题是否有两个或二十二个主题。


Terry Olsen写道:
I''m just curious why you chose four threads. I mean, if you want something
optimal, I would think the thread count is based on a buffer size. In
theory, I doubt the question matters if there was two or twenty-two threads.

"Terry Olsen" wrote:

我需要能够从大约4

不同的线程同时写入文件。我正在开发一个程序,它将下载部分

文件并组合这些部分。每个线程都有一个零偏移量和一个

长度来写。没有任何线程会在文件位置重叠。


是否可以让多个线程打开(共享)文件?我是b / b
猜测我会使用某种文件流进行某种共享。寻找

一些指针和/或示例。谢谢!
I need to be able to write to a file simultaneously from approximately 4
different threads. I''m working on a program that will download parts of a
file and combine the parts. Each thread will have an offset from zero and a
length to write. None of the threads will overlap in the file position.

Is it possible to have the file open (shared) by multiple threads? I''m
guessing that i''d use a filestream with some sort of sharing. Looking for
some pointers and/or examples. Thanks!


这篇关于可以从多个线程写入文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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