-
Notifications
You must be signed in to change notification settings - Fork 15.3k
Open
Labels
filesystemC++17 std::filesystemC++17 std::filesystemlibc++libc++ C++ Standard Library. Not GNU libstdc++. Not libc++abi.libc++ C++ Standard Library. Not GNU libstdc++. Not libc++abi.
Description
When I use multiple threads to copy a file without locking, there are occasional instances where the copy_file operation seems to get stuck indefinitely.
By adding print logs before and after calling copy_file, it was discovered that the process was getting stuck during the call to copy_file_impl_copy_file_range.The main body of copy_file_impl_copy_file_range is a loop.
do {
ssize_t res;
if ((res = ::copy_file_range(read_fd.fd, &off_in, write_fd.fd, &off_out, count, 0)) == -1) {
ec = capture_errno();
return false;
}
count -= res;
} while (count > 0);
In the above scenario, the value of res was returned as 0. It appears that one of the two threads was continuously copying empty data.Why does this situation occur? Should we add a condition to check if res is 0 to prevent entering an infinite loop?
Metadata
Metadata
Assignees
Labels
filesystemC++17 std::filesystemC++17 std::filesystemlibc++libc++ C++ Standard Library. Not GNU libstdc++. Not libc++abi.libc++ C++ Standard Library. Not GNU libstdc++. Not libc++abi.