Have you missed maybe an *other* important detail in your pseudocode? If you really want help, provide small working example demonstrating your problem. Try it with reference compiler (msvc/gcc) to make sure it is not a compiler issue.Well spotted Colin thank you for taking the time to reply, but in my real
code i was incremented. I supplied this pseudo code to demonstrate how I was
using the library just in case my usage was incorrect.
Don't hurryI simply can understand why this doesn't work. I am using 64 bit builds of
#include
"stdafx.h"#include
<iostream>#include
<fstream>#include
<boost/date_time/posix_time/posix_time.hpp>#include
<boost/interprocess/exceptions.hpp>#include
<boost/interprocess/sync/file_lock.hpp>using
namespace boost::interprocess ;using
namespace boost::posix_time ;int
_tmain(int argc, _TCHAR* argv[]){
std::string m_FileName(
"./locktest.txt") ;std::ofstream os ;
os.open(m_FileName.c_str(), std::ios_base::out | std::ios_base::binary | std::ios_base::app) ;
try{
if (os.is_open()){
file_lock fileLock(m_FileName.c_str()) ;
ptime pt(second_clock::local_time()) ;
os.setf(std::ios::fixed, std::ios::floatfield) ;
os.precision(3) ;
if (fileLock.timed_lock(pt += seconds(5))){
try{
// Do rows for (int o = 0; o < 48; o++){
os << "This is row " << o << " of 48" << " and this is just text" << "\n" ;// Do columns
for (int i = 0; i < 51; i++)
{
os << i << "\t" ;
}
}
fileLock.unlock() ;
}
catch (interprocess_exception& e)
{
std::cout << e.what() ;
}
catch (std::ofstream::failure e)
{
std::cout << e.what() ;
}
}
else
{
std::cout <<
"No lock on file!" ;}
os.close() ;
}
else{
std::cout <<
"File not opened!" ;}
}
catch (std::exception& e){
std::cout << e.what() ;
}
std::cout <<
"Press a key to close." ;std::cin.get() ;
return 0 ;}
Thank you.
--
Bill