Closed
Description
Currently we provide os::getcwd()
/os::change_dir()
via OS functions (libc::getcwd
or GetCurrentDirectory), but curdir information is maintained per-process, which means it is not thread-safe nor task-safe.
Here is a sample code for current dir race:
use std::os;
use std::io;
use std::io::fs;
fn main() {
let tmp_path = os::tmpdir();
for i in range(0u, 20u) {
let path = tmp_path.join(i.to_str());
do spawn {
io::result(|| fs::mkdir(&path, io::UserRWX));
let _ret = os::change_dir(&path);
let cur = os::getcwd();
if cur != path {
println!("expected {:s} but found {:s}",
path.as_str().unwrap(), cur.as_str().unwrap());
}
}
}
}
So we must ban them and implement "current directory" using task-local storage.
Metadata
Metadata
Assignees
Labels
No labels