Can you have multiple cursors for the same thread? Will it be thread safe?

I have several threads and I want each of them to process part of my file. Can I have one ifstream object for this and get them to read different parts at the same time? Parts do not overlap, so the same line will not be processed by two threads. If so, how do you get multiple cursors?

+4
source share
3 answers

The only one std::ifstreamassociated with exactly one cursor (there is a method seekgand tellgassociated with std::ifstreamdirectly).

, std::ifstream , - , ( , , ).

, std::ifstream . , . , "" (: ).

0

++ (., , ).

, "". , concurrency .

ifstream (.. ) concurrency . - , , - .

, .. . , (. ).

0

Looking at the FILE struct , it seems that there is a pointer inside the FILE, char* curppointing to the current active pointer, which may mean that for each FILE object you will have one specific part of the file.
This is in C, I don’t know how ifstream works, and if it uses a FILE object / it is built as a FILE object. It may not help you at all, but I thought it would be interesting to share this little information and that it might help someone.

0
source

Source: https://habr.com/ru/post/1676456/


All Articles