Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.c++ > #5676 > unrolled thread

std::ifstream multithread

Started byPhilipp Kraus <philipp.kraus@flashpixx.de>
First post2011-05-27 12:22 +0200
Last post2011-05-27 15:17 +0000
Articles 6 — 3 participants

Back to article view | Back to comp.lang.c++


Contents

  std::ifstream multithread Philipp Kraus <philipp.kraus@flashpixx.de> - 2011-05-27 12:22 +0200
    Re: std::ifstream multithread Victor Bazarov <v.bazarov@comcast.invalid> - 2011-05-27 08:31 -0400
      Re: std::ifstream multithread Philipp Kraus <philipp.kraus@flashpixx.de> - 2011-05-27 15:04 +0200
        Re: std::ifstream multithread Victor Bazarov <v.bazarov@comcast.invalid> - 2011-05-27 09:19 -0400
          Re: std::ifstream multithread Philipp Kraus <philipp.kraus@flashpixx.de> - 2011-05-27 16:51 +0200
    Re: std::ifstream multithread Jorgen Grahn <grahn+nntp@snipabacken.se> - 2011-05-27 15:17 +0000

#5676 — std::ifstream multithread

FromPhilipp Kraus <philipp.kraus@flashpixx.de>
Date2011-05-27 12:22 +0200
Subjectstd::ifstream multithread
Message-ID<irnu08$b8f$1@online.de>
Hello,

I must read a lot of files like this

std::ifstream l_file;	

l_file.open(p_str1.c_str(), std::ifstream::binary);
std::copy( std::istream_iterator<char>(l_file), 
std::istream_iterator<char>(), 
std::ostreambuf_iterator<char>(&l_deflate) );
l_file.close();

I deflate the file content with bzip. I would do this in a multithread 
content, so my question is, can I do this without any problems during 
reading?
In some cases two thread can use the same file (p_str1 is in two 
threads equal). Can i read the same file out of two thread or is a 
mutex required?

Thanks

Phil

[toc] | [next] | [standalone]


#5681

FromVictor Bazarov <v.bazarov@comcast.invalid>
Date2011-05-27 08:31 -0400
Message-ID<iro5ia$65h$1@dont-email.me>
In reply to#5676
On 5/27/2011 6:22 AM, Philipp Kraus wrote:
> I must read a lot of files like this
>
> std::ifstream l_file;
>
> l_file.open(p_str1.c_str(), std::ifstream::binary);
> std::copy( std::istream_iterator<char>(l_file),
> std::istream_iterator<char>(),
> std::ostreambuf_iterator<char>(&l_deflate) );
> l_file.close();
>
> I deflate the file content with bzip. I would do this in a multithread
> content, so my question is, can I do this without any problems during
> reading?
> In some cases two thread can use the same file (p_str1 is in two threads
> equal). Can i read the same file out of two thread or is a mutex required?

You need to consult your compiler and/or standard library manual.  C++ 
(as it stands now) claims nothing WRT threads and reentrancy.  In the 
new Standard there are specific provisions for supporting 
multithreading, but not in the current one.

V
-- 
I do not respond to top-posted replies, please don't ask

[toc] | [prev] | [next] | [standalone]


#5684

FromPhilipp Kraus <philipp.kraus@flashpixx.de>
Date2011-05-27 15:04 +0200
Message-ID<iro7gi$irt$1@online.de>
In reply to#5681
On 2011-05-27 14:31:05 +0200, Victor Bazarov said:

> On 5/27/2011 6:22 AM, Philipp Kraus wrote:
>> I must read a lot of files like this
>> 
>> std::ifstream l_file;
>> 
>> l_file.open(p_str1.c_str(), std::ifstream::binary);
>> std::copy( std::istream_iterator<char>(l_file),
>> std::istream_iterator<char>(),
>> std::ostreambuf_iterator<char>(&l_deflate) );
>> l_file.close();
>> 
>> I deflate the file content with bzip. I would do this in a multithread
>> content, so my question is, can I do this without any problems during
>> reading?
>> In some cases two thread can use the same file (p_str1 is in two threads
>> equal). Can i read the same file out of two thread or is a mutex required?
> 
> You need to consult your compiler and/or standard library manual.

I use g++ and Visual Studio, du you know anything about it? In my 
option the OS should be manage the access to the files.

Thx

Phil

[toc] | [prev] | [next] | [standalone]


#5688

FromVictor Bazarov <v.bazarov@comcast.invalid>
Date2011-05-27 09:19 -0400
Message-ID<iro8d3$pbb$1@dont-email.me>
In reply to#5684
On 5/27/2011 9:04 AM, Philipp Kraus wrote:
> On 2011-05-27 14:31:05 +0200, Victor Bazarov said:
>
>> On 5/27/2011 6:22 AM, Philipp Kraus wrote:
>>> I must read a lot of files like this
>>>
>>> std::ifstream l_file;
>>>
>>> l_file.open(p_str1.c_str(), std::ifstream::binary);
>>> std::copy( std::istream_iterator<char>(l_file),
>>> std::istream_iterator<char>(),
>>> std::ostreambuf_iterator<char>(&l_deflate) );
>>> l_file.close();
>>>
>>> I deflate the file content with bzip. I would do this in a multithread
>>> content, so my question is, can I do this without any problems during
>>> reading?
>>> In some cases two thread can use the same file (p_str1 is in two threads
>>> equal). Can i read the same file out of two thread or is a mutex
>>> required?
>>
>> You need to consult your compiler and/or standard library manual.
>
> I use g++ and Visual Studio, du you know anything about it? In my option
> the OS should be manage the access to the files.

Sorry, specific compilers are discussed in their specific newsgroups.  A 
particular OS is discussed in its newsgroup.  Use the right venue for 
your inquiries, OK?  Or just google.

V
-- 
I do not respond to top-posted replies, please don't ask

[toc] | [prev] | [next] | [standalone]


#5705

FromPhilipp Kraus <philipp.kraus@flashpixx.de>
Date2011-05-27 16:51 +0200
Message-ID<irodp9$o1r$1@online.de>
In reply to#5688
On 2011-05-27 15:19:31 +0200, Victor Bazarov said:

> On 5/27/2011 9:04 AM, Philipp Kraus wrote:
>> On 2011-05-27 14:31:05 +0200, Victor Bazarov said:
>> 
>>> On 5/27/2011 6:22 AM, Philipp Kraus wrote:
>>>> I must read a lot of files like this
>>>> 
>>>> std::ifstream l_file;
>>>> 
>>>> l_file.open(p_str1.c_str(), std::ifstream::binary);
>>>> std::copy( std::istream_iterator<char>(l_file),
>>>> std::istream_iterator<char>(),
>>>> std::ostreambuf_iterator<char>(&l_deflate) );
>>>> l_file.close();
>>>> 
>>>> I deflate the file content with bzip. I would do this in a multithread
>>>> content, so my question is, can I do this without any problems during
>>>> reading?
>>>> In some cases two thread can use the same file (p_str1 is in two threads
>>>> equal). Can i read the same file out of two thread or is a mutex
>>>> required?
>>> 
>>> You need to consult your compiler and/or standard library manual.
>> 
>> I use g++ and Visual Studio, du you know anything about it? In my option
>> the OS should be manage the access to the files.
> 
> Sorry, specific compilers are discussed in their specific newsgroups.  
> A particular OS is discussed in its newsgroup.  Use the right venue for 
> your inquiries, OK?  Or just google.

Thx

[toc] | [prev] | [next] | [standalone]


#5707

FromJorgen Grahn <grahn+nntp@snipabacken.se>
Date2011-05-27 15:17 +0000
Message-ID<slrnitvg4e.gtj.grahn+nntp@frailea.sa.invalid>
In reply to#5676
On Fri, 2011-05-27, Philipp Kraus wrote:
> Hello,
>
> I must read a lot of files like this
>
> std::ifstream l_file;	
>
> l_file.open(p_str1.c_str(), std::ifstream::binary);
> std::copy( std::istream_iterator<char>(l_file), 
> std::istream_iterator<char>(), 
> std::ostreambuf_iterator<char>(&l_deflate) );
> l_file.close();
>
> I deflate the file content with bzip. I would do this in a multithread 
> content, so my question is, can I do this without any problems during 
> reading?
> In some cases two thread can use the same file (p_str1 is in two 
> threads equal). Can i read the same file out of two thread or is a 
> mutex required?

You mean you have several streams reading the same file, which is
opened many times.  I'd say that is very unlikely to be a problem, if
your compiler/standard library handles threading at all.

/Jorgen

-- 
  // Jorgen Grahn <grahn@  Oo  o.   .  .
\X/     snipabacken.se>   O  o   .

[toc] | [prev] | [standalone]


Back to top | Article view | comp.lang.c++


csiph-web