Skip to content

Commit

Permalink
Ceci n'est pas une pipe
Browse files Browse the repository at this point in the history
  • Loading branch information
vitaut committed Dec 29, 2023
1 parent d83c1b8 commit d5823aa
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 0 deletions.
1 change: 1 addition & 0 deletions include/fmt/os.h
Original file line number Diff line number Diff line change
Expand Up @@ -315,6 +315,7 @@ class FMT_API file {

// Creates a pipe setting up read_end and write_end file objects for reading
// and writing respectively.
// DEPRECATED! Taking files as out parameters is deprecated.
static void pipe(file& read_end, file& write_end);

// Creates a buffered_file object associated with this file and detaches
Expand Down
5 changes: 5 additions & 0 deletions test/scan-test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,7 @@ TEST(scan_test, file) {
}

TEST(scan_test, lock) {

fmt::file read_end, write_end;
fmt::file::pipe(read_end, write_end);

Expand All @@ -152,6 +153,7 @@ TEST(scan_test, lock) {
write_end.close();
});

std::atomic<int> count = 0;
fmt::buffered_file f = read_end.fdopen("r");
auto fun = [&]() {
int value = 0;
Expand All @@ -161,12 +163,15 @@ TEST(scan_test, lock) {
EXPECT_EQ(value, 42);
break;
}
++count;
}
};
std::thread consumer1(fun);
std::thread consumer2(fun);
producer.join();
consumer1.join();
consumer2.join();
EXPECT_EQ(count, 1000);

}
#endif // FMT_USE_FCNTL

0 comments on commit d5823aa

Please sign in to comment.