
On Fri, Jul 29, 2011 at 8:42 AM, <Viatcheslav.Sysoltsev@h-d-gmbh.de> wrote:
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.
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.
I simply can understand why this doesn't work. I am using 64 bit builds of
Don't hurry
Hi, I appreciate the example was useless and of course missing the timed_lock request, so apologies for wasting your time. I have now provided a complete example as requested, as a Win32 console app built in x64. However, I am unable to test on any compiler other the Intel as I do not have the applicable libraries, but I suspect this may not be a compiler issue. I suspect the real problem lies between the seat and the keyboard. Not to sure what you meant by "Don't hurry" but I suspect there may be an odour or urine in the air. #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