std::ifstream multithread

P

Philipp Kraus

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::eek:streambuf_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
 
V

Victor Bazarov

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::eek:streambuf_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
 
P

Philipp Kraus

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
 
V

Victor Bazarov

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
 
P

Philipp Kraus

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
 
J

Jorgen Grahn

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::eek:streambuf_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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Members online

No members online now.

Forum statistics

Threads
473,968
Messages
2,570,152
Members
46,697
Latest member
AugustNabo

Latest Threads

Top