Need clarification on file_lock documentation
Nadie ha tomado este issue todavía.
Evaluación
- Dificultad
- 4/5
- Tiempo estimado
- 3-5 días
- Aptitud para principiantes
- 35/100
- Tipo de issue
- Documentación
- Claridad
- Necesita aclaración
- Estado de actividad
- Estancado
- Stack tecnológico
- cpp
Línea de trabajo
Comience con la documentación de boost::interprocess::file_lock y reproduzca el comportamiento usando el ejemplo de C++ incluido en el issue. Determine si las indicaciones documentadas sobre hilos y procesos son incorrectas o simplemente poco claras; el trabajo está terminado cuando la cuestión de documentación o implementación tenga una explicación resuelta y verificada.
Escrito por el modelo de indexación a partir del texto del issue.
Descripción
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
- Lenguaje dominante
- C++
- Estrellas
- 185
- Forks
- 131
- Métricas de merge de PR
- Sin PR fusionados en 30 d
Guía de contribución
No hay ninguna guía de contribución indexada para este repositorio
Primeros pasos
- Lee el issue completo y luego la guía de contribución del proyecto.
- Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
- Haz un fork del repositorio y trabaja en una rama.
- Abre un pull request que haga referencia al número del issue.
Más de boostorg/interprocess
-
Dificultad 1/5 Menos de una hora Aptitud para principiantes 68/100
boostorg/interprocess#196 · 1 reacción ·
-
Dificultad 5/5 Más de una semana Aptitud para principiantes 35/100
boostorg/interprocess#279 ·
-
Dificultad 4/5 3-5 días Aptitud para principiantes 35/100
boostorg/interprocess#274 · 1 comentario ·
-
Dificultad 5/5 Más de una semana Aptitud para principiantes 28/100
boostorg/interprocess#268 · 4 comentarios ·
-
Semaphore use in signals Abierto
Dificultad 5/5 Más de una semana Aptitud para principiantes 35/100
boostorg/interprocess#262 · 2 comentarios ·
Todos los issues de boostorg/interprocess
Issues similares
-
[CI] Nightly Clang build broken: structured binding captured in a lambda in FileDataSource.cpp Abiertobug build
Dificultad 1/5 Menos de una hora Aptitud para principiantes 91/100
facebookincubator/velox#19194 ·
-
JIT-compiled number -> Decimal conversion silently overflows instead of raising DECIMAL_OVERFLOW Abiertofuzz
Dificultad 2/5 1-3 horas Aptitud para principiantes 82/100
ClickHouse/ClickHouse#122114 ·
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 84/100
-
module/agent platform/macos type/bug/regression
Dificultad 2/5 1-3 horas Aptitud para principiantes 88/100
-
enhancement PyCDE
Dificultad 2/5 1-3 horas Aptitud para principiantes 78/100