Need clarification on file_lock documentation
まだ誰も着手していません。
評価
- 難易度
- 4/5
- 見積もり時間
- 3〜5日
- 初心者へのやさしさ
- 35/100
- issue の種類
- ドキュメント
- 明瞭さ
- 説明が足りない
- 活発さ
- 停滞
- 技術スタック
- cpp
調査の方向性
boost::interprocess::file_lock のドキュメントから始め、issue に含まれている C++ の例を使って動作を再現してください。文書化されているスレッドとプロセスに関する指針が誤っているのか、単に不明確なのかを判断してください。ドキュメントまたは実装に関する問題について、解決済みで検証された説明が得られれば完了です。
索引モデルが issue の本文から書いたものです。
説明
The documentation of boost::interprocess::file_lock has some cautions on synchronization limitations:
- It's unspecified if a file_lock synchronizes two threads from the same process.
- It's unspecified if a process can use two file_lock objects pointing to the same file.
But then gives the guidance:
- For each file, use a single file_lock object per process.
- Use the same thread to lock and unlock a file.
I then created the following example:
https://wandbox.org/permlink/dO2rRDCHVWBE3pGrhttps://wandbox.org/permlink/3CNfkA3RcMkwbd2v
#include <fstream>
#include <iostream>
#include <cstdlib>
#include <boost/interprocess/sync/file_lock.hpp>
#include <boost/interprocess/sync/scoped_lock.hpp>
#include <boost/filesystem.hpp>
#include <mutex>
#include <thread>
#include <chrono>
int main()
{
std::ofstream("f.txt");
boost::interprocess::file_lock lock("f.txt");
std::mutex mtx;
const size_t max = 100;
size_t t1Count = 0;
std::thread
t1
(
[&lock,&t1Count,&mtx,max]()
{
while(t1Count < max)
{
//std::lock_guard<std::mutex> mtxLock(mtx);
boost::interprocess::scoped_lock<boost::interprocess::file_lock> guard(lock);
std::cout << "Number 1" << std::endl;
t1Count++;
std::this_thread::sleep_for(std::chrono::milliseconds(1));
}
}
);
size_t t2Count = 0;
std::thread
t2
(
[&lock,&t2Count,&mtx,max]()
{
while(t2Count < max)
{
//std::lock_guard<std::mutex> mtxLock(mtx);
boost::interprocess::scoped_lock<boost::interprocess::file_lock> guard(lock);
std::cout << "Number 2" << std::endl;
t2Count++;
std::this_thread::sleep_for(std::chrono::milliseconds(1));
}
}
);
t1.join();
t2.join();
return 0;
}
It only works properly if the std::mutex is used in addition to the file_lock. That was originally my thought when I read "It's unspecified if a file_lock synchronizes two threads from the same process.", but it seemed like I was following the guidance "Use the same thread to lock and unlock a file.". If I haven't messed anything up, I would probably update the documentation to say something like:
"If utilitizing the file_lock from multiple threads within the same process, synchronize access to the file_lock with an intraprocess synchronization mechanism such as a mutex."
Otherwise, is it a bug?
Thanks,
Rob
- 主要言語
- C++
- スター
- 185
- フォーク
- 131
- PR マージ指標
- 30日以内にマージされた PR はありません
コントリビューションガイド
このリポジトリのコントリビューションガイドは索引されていません
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
boostorg/interprocess のほかの issue
-
難易度 1/5 1時間未満 初心者へのやさしさ 68/100
boostorg/interprocess#196 · リアクション 1 件 ·
-
難易度 5/5 1週間以上 初心者へのやさしさ 35/100
boostorg/interprocess#279 ·
-
難易度 4/5 3〜5日 初心者へのやさしさ 35/100
boostorg/interprocess#274 · コメント 1 件 ·
-
難易度 5/5 1週間以上 初心者へのやさしさ 28/100
boostorg/interprocess#268 · コメント 4 件 ·
-
難易度 5/5 1週間以上 初心者へのやさしさ 35/100
boostorg/interprocess#262 · コメント 2 件 ·
boostorg/interprocess の issue をすべて見る
似ている issue
-
bug build
難易度 1/5 1時間未満 初心者へのやさしさ 91/100
facebookincubator/velox#19194 ·
-
JIT-compiled number -> Decimal conversion silently overflows instead of raising DECIMAL_OVERFLOW オープンfuzz
難易度 2/5 1〜3時間 初心者へのやさしさ 82/100
ClickHouse/ClickHouse#122114 ·
-
難易度 2/5 1〜3時間 初心者へのやさしさ 84/100
-
module/agent platform/macos type/bug/regression
難易度 2/5 1〜3時間 初心者へのやさしさ 88/100
-
enhancement PyCDE
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100