|
Boost Users : |
Subject: Re: [Boost-users] [IPC Named Mutex]
From: Tom Kent (lists_at_[hidden])
Date: 2015-04-16 09:53:20
On Thu, Apr 16, 2015 at 3:01 AM, Lorenzo Trivelli <
trivelli.lorenzo_at_[hidden]> wrote:
> Hi to everyone,
> I'm experiencing a strange behaviour of named mutex on
> a windows 2008 machine.
> symptoms: when the system event log is empty, creation
> of named mutex fails with a boost::interprocess::interprocess:exception
> with msg boost::interprocess_exception::library_error.
> Now some data:
> 1) Boost 1.57.0 + stlport 5.2
> 2) VS 2005
> 3) Target Environment: Win 2008/32
> 3) after a night of code digging I managed to crete a small sample
> which raises the exception:
>
> #include <boost/shared_ptr.hpp>
> #include <boost/interprocess/sync/named_mutex.hpp>
> #include <boost/interprocess/sync/scoped_lock.hpp>
> #include <iostream>
>
> typedef boost::shared_ptr<boost::interprocess::named_mutex>
> safe_ipc_mx;
>
> static safe_ipc_mx __mx;
> int main(void) {
> system("pause");
> try {
> __mx = safe_ipc_mx(new
> boost::interprocess::named_mutex(boost::interprocess::open_or_create_t(),"JAEGER"));
> std::cout << std::endl << "Mutex created !" << std::endl;
> } catch(boost::interprocess::interprocess_exception const& e) {
> std::cout << std::endl << "Mutex creation error " <<
> e.what() << " /" << e.get_error_code() << " /" << e.get_native_error();
> }
> system("pause");
> return 0;
>
> }
>
>
I tried it also, and got the same result. I also tried with msvc-12.0, same
result.
> as far as I digged, it seems that the trouble is in the
> winapi::get_last_bootup_time(stamp) call
> in shared_dir_helpers.hpp, but up to now I had not been able to reproduce
> it on a machine with
> all the debugging tools installed
>
get_last_bootup_time() looks through the system event log for event ID ==
6005 (event log started)...since the event log was cleared out, this is not
found. I guess that is a bug in boost.
One thing you could try...in interprocess's win32_api.hpp, there is another
implementation of get_last_bootup_time() which uses WMI instead of the
event log (there were warnings in the source about WMI not supporting
hibernation/clock changes correctly, so beware). If you define
BOOST_INTERPROCESS_BOOTSTAMP_IS_LASTBOOTUPTIME
it should use that other version...give that a try. (in visual studio
Project Properties -> C/C++ -> Preprocessor -> Preprocessor Definitions:
add a semi colon ';' then the above item)
That worked for me on windows 7.
I submitted a pull request to automatically fallback to WMI if the event
log started event isn't in the log.
https://github.com/boostorg/interprocess/pull/18
Tom
Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net