Sync File
Files that can be read concurrently.
std::fs::File
is Sync
but reading concurrently from it results in race
conditions, because the OS has a single cursor which is advanced and used
by several threads.
SyncFile
solves this problem by using platform-specific extensions to do
positional I/O, so the cursor of the file is not shared.
Example
use Read;
use SyncFile;
/// Reads a file byte by byte.
/// Don't do this in real code !
// Open a file
let f = open?;
let f_clone = f.clone;
// Read it concurrently
let thread = spawn;
let res1 = read_all?;
let res2 = thread.join.unwrap?;
// Both clones read the whole content
// This would not work with `std::fs::File`
assert_eq!;
assert_eq!;
License
Licensed under either of
- Apache License, Version 2.0 (LICENSE-APACHE or http://www.apache.org/licenses/LICENSE-2.0)
- MIT license (LICENSE-MIT or http://opensource.org/licenses/MIT)
at your option.
Contribution
Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.