Click here to Skip to main content
15,889,281 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
AnswerRe: String Conversion Pin
Mike Certini25-Jan-11 17:28
Mike Certini25-Jan-11 17:28 
GeneralRe: String Conversion Pin
Andrew Brock25-Jan-11 21:56
Andrew Brock25-Jan-11 21:56 
AnswerRe: String Conversion Pin
Stefan_Lang27-Jan-11 3:28
Stefan_Lang27-Jan-11 3:28 
QuestionConvert String Pin
DraC_fri25-Jan-11 12:47
DraC_fri25-Jan-11 12:47 
AnswerRe: Convert String Pin
Yusuf25-Jan-11 13:22
Yusuf25-Jan-11 13:22 
AnswerRe: Convert String Pin
Luc Pattyn25-Jan-11 13:23
sitebuilderLuc Pattyn25-Jan-11 13:23 
AnswerRe: Convert String Pin
Maximilien25-Jan-11 13:44
Maximilien25-Jan-11 13:44 
Questionboost::named_mutex not released after process abort Pin
WernerP25-Jan-11 4:06
WernerP25-Jan-11 4:06 
OS Version: Windows XP Pro
boost Version: 1.44.0

Hi,

I want to monitor, whether a certain process is running.
The program of the process is written in C++ and is
a console app.

I've chosen the mutex concept, because I want to restrict usage
of the program's main to exactly one thread.

First I used the example from the boost site, which places the scoped_lock
within the main routine's block. But when the app was terminated via
the close button of the console window
the scoped_lock destructor was not called

which had a negative side effect: The mutex is associated with a file Hmmm | :|
in the All Users\Application Data tree,
directory boost_interprocess
and if this file is not deleted, the mutex can not be acquired, although
it is no more referenced by any application.

Hence I wrapped the mutex into a global object
(1) to instantiate it as soon as possible
(2) to release it under as many circumstances of program termination as possible via
the wrapper's destructor.

This is the wrapper's class - you can see
the mutex is
non-blocking and
controlled via a scoped lock
<br />
struct ApplicationLock<br />
{<br />
    ApplicationLock() : appmutex(open_or_create, "SilvaCoreMutex"), applock(appmutex, try_to_lock)<br />
    {}<br />
    bool alreadylocked()<br />
    {<br />
        return (applock == 0);<br />
    }<br />
private:<br />
    named_mutex appmutex;<br />
    scoped_lock<named_mutex> applock;<br />
};<br />
<br />
ApplicationLock appliclock;<br />


If the console window is closed, the desctructor is called and
the mutex released. But if the process is terminated due
to a crash or aborted via the task manager,
the mutex is not released. Even a system restart doesn't release it.

I thought a mutex should
be held in a memory shared area and exclusively depend on this shared area
and never depend on anything which is stored in the file system.

How can I get rid of that mutex, when it is no more referenced
by any application. Have I chosen the wrong concept? Have I
misunderstood the boost mutex technique?

Thanks in advance
Werner
AnswerRe: boost::named_mutex not released after process abort Pin
T210225-Jan-11 19:41
T210225-Jan-11 19:41 
GeneralRe: boost::named_mutex not released after process abort Pin
WernerP26-Jan-11 0:16
WernerP26-Jan-11 0:16 
GeneralRe: boost::named_mutex not released after process abort Pin
TheGreatAndPowerfulOz26-Jan-11 9:57
TheGreatAndPowerfulOz26-Jan-11 9:57 
GeneralRe: boost::named_mutex not released after process abort [modified] Pin
WernerP26-Jan-11 11:52
WernerP26-Jan-11 11:52 
AnswerRe: boost::named_mutex not released after process abort Pin
Chuck O'Toole26-Jan-11 18:20
Chuck O'Toole26-Jan-11 18:20 
GeneralRe: boost::named_mutex not released after process abort [modified] Pin
WernerP26-Jan-11 21:48
WernerP26-Jan-11 21:48 
GeneralRe: boost::named_mutex not released after process abort Pin
Chuck O'Toole26-Jan-11 23:42
Chuck O'Toole26-Jan-11 23:42 
QuestionNeed interface index for recvd UDP packets Pin
Dave_25-Jan-11 3:50
Dave_25-Jan-11 3:50 
AnswerRe: Need interface index for recvd UDP packets Pin
HimanshuJoshi25-Jan-11 5:43
HimanshuJoshi25-Jan-11 5:43 
QuestionSet AutoRun fail under win 7 [modified][solved] Pin
yu-jian25-Jan-11 2:57
yu-jian25-Jan-11 2:57 
AnswerRe: Set AutoRun fail under win 7 Pin
Code-o-mat25-Jan-11 3:17
Code-o-mat25-Jan-11 3:17 
AnswerRe: Set AutoRun fail under win 7 Pin
CPallini25-Jan-11 3:20
mveCPallini25-Jan-11 3:20 
AnswerRe: Set AutoRun fail under win 7 Pin
Hans Dietrich25-Jan-11 3:47
mentorHans Dietrich25-Jan-11 3:47 
AnswerRe: Set AutoRun fail under win 7 Pin
Richard MacCutchan25-Jan-11 4:47
mveRichard MacCutchan25-Jan-11 4:47 
GeneralRe: Set AutoRun fail under win 7 Pin
yu-jian25-Jan-11 6:28
yu-jian25-Jan-11 6:28 
AnswerRe: Set AutoRun fail under win 7 Pin
yu-jian25-Jan-11 6:13
yu-jian25-Jan-11 6:13 
Questionshadow copy, deep copy and bitwie copy by constructor Pin
aesthetic.crazy25-Jan-11 2:26
aesthetic.crazy25-Jan-11 2:26 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.