Issue 169261
Summary [libcxx] copy_file enters an infinite loop in a multithreaded environment.
Labels libc++
Assignees
Reporter Costatie
    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?
_______________________________________________
llvm-bugs mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to