I wonder if there is any way to lock and unlock a file in Linux when I open a file using fopen
(not open
)?
Based on Stack Overflow question
The below code is not letting me lock the file using lockf, flock works fine though
#include
#include
#include
#include
#include
#include
#include
using namespace std;
void append()
{
FILE *fp=fopen("a.txt","a");
if(fp)
{
cout< v;
//#pragma omp parallel for
for(int i=0;i<1000;++i)
{
v.push_back(new thread(append));
//append();
}
for(auto y:v)
{
y->join();
delete y;
}
return 0;
}