Real Software Forums

The forum for Real Studio and other Real Software products.
[ REAL Software Website | Board Index ]
It is currently Sun Sep 15, 2019 9:20 am
xojo

All times are UTC - 5 hours




Post new topic Reply to topic  [ 9 posts ] 
Author Message
 Post subject: Location of Mutex Property and Resulting Effectiveness
PostPosted: Wed Mar 19, 2008 7:17 pm 
Offline

Joined: Fri Sep 30, 2005 8:30 am
Posts: 254
In Ubuntu 7.1, RB 2008r1:

I create a Global property in a module of type Mutex:

mtxMutex as Mutex

When my app launches, it constructs the mutex:

mtxMutex = New Mutex( "MyCoolApp" )

When the app launches, it creates a file named "MyCoolApp" in \tmp which appears and disappears as the Mutex is created and released.

If I make a copy of my app and try to launch it while the first copy is running to test the mutex, the mutex can't be locked --- so my app calls Quit() like this:

mtxMutex = New Mutex( "MyCoolApp" )

bTryEnter = mtxMutex.TryEnter()

If bTryEnter = False Then
MsgBox "Already running."
Quit()
End If


But, when Quit() is called by the second copy, it destroys the Mutex --- even though it was created by the *first* copy of the app. Once the mutex is destroyed by the Quit() call in the second app, I can then launch the second copy of the app, which happily creates the mutex all over again. (Interestingly, the same thing happens if I try to launch the first copy of the application again instead of a second copy.)

BUT: If I store the Mutex property in the App class of the project (instead of a module), everything works as expected. The second app does not destroy the mutex --- the first mutex is not destroyed until the first app that created it quits.

Is this a bug? Or am I misunderstanding something. On OS X, it doesn't matter whether the Mutex is stored in a module or as part of the App class.


Top
 Profile  
Reply with quote  
 Post subject: Re: Location of Mutex Property and Resulting Effectiveness
PostPosted: Thu Mar 20, 2008 12:09 am 
Offline

Joined: Mon Jul 17, 2006 10:39 am
Posts: 1718
Keep in mind that Quit() does not quit immediately. It allows threads to unwind, Close events to be triggered, etc... That said, are you calling Mutex.Leave() somewhere else that might be called in the natural app shutdown process? Set breakpoints on every occurrence to make sure, if you want.

If you eliminate that possibility and still see that behaviour, then yes, I'd consider it a bug.

_________________
Kenneth McCleary
ken@mccleary.me


Top
 Profile  
Reply with quote  
 Post subject: Re: Location of Mutex Property and Resulting Effectiveness
PostPosted: Thu Mar 20, 2008 7:24 am 
Offline

Joined: Fri Sep 30, 2005 8:30 am
Posts: 254
kendoll wrote:
Keep in mind that Quit() does not quit immediately. It allows threads to unwind, Close events to be triggered, etc... That said, are you calling Mutex.Leave() somewhere else that might be called in the natural app shutdown process?


Thank you.

I'm not sure I follow you. The second copy of the app should NOT be able to destroy the mutex created by the first app. The second app did not get a lock, nor did it create the Mutex so it shouldn't call .Leave() --- it doesn't have access to the resource --- by its own "admission" (returning False to TryEnter). Despite not creating the mutex or having a lock, the second app at Quit() then destroys the mutex created by the first app.

Quit() seems to be finishing ok, the problem is that the second app is destroying a mutex it did not create and only if the mutex is a Property in a module. If the mutex is a property in the App class, everything works according to design.

You have given me an idea, though, that might serve as a workaround --- in Linux, I could try setting the Mutex to Nil before calling Quit(). Perhaps that will keep the physical Mutex file from being destroyed.


Top
 Profile  
Reply with quote  
 Post subject: Re: Location of Mutex Property and Resulting Effectiveness
PostPosted: Thu Mar 20, 2008 9:38 am 
Offline

Joined: Fri Sep 30, 2005 8:30 am
Posts: 254
fitzbew wrote:
...might serve as a workaround --- in Linux, I could try setting the Mutex to Nil before calling Quit(). Perhaps that will keep the physical Mutex file from being destroyed.


This didn't work. Setting the mutex to Nil in the second app destroys the Mutex created by the first app immediately.

I think I will go ahead and report this to REAL as a bug.

Fortunately, there seems to be an easy workaround: On Linux, store the Mutex in the App class and not a module.


Top
 Profile  
Reply with quote  
 Post subject: Re: Location of Mutex Property and Resulting Effectiveness
PostPosted: Fri Mar 21, 2008 5:25 pm 
Offline

Joined: Mon Jul 17, 2006 10:39 am
Posts: 1718
[quote=fitzbew]Setting the mutex to Nil in the second app destroys the Mutex created by the first app immediately.[/quote]

I'd have to wonder if that's part of the bug right there. Maybe when the mutex in the module goes out of scope, it calls the wrong code to destroy itself.

Do you get the same behaviour if you use a shared property within a class?

_________________
Kenneth McCleary
ken@mccleary.me


Top
 Profile  
Reply with quote  
 Post subject: Re: Location of Mutex Property and Resulting Effectiveness
PostPosted: Fri Mar 21, 2008 5:36 pm 
Offline

Joined: Fri Sep 30, 2005 8:30 am
Posts: 254
kendoll wrote:
fitzbew wrote:
Setting the mutex to Nil in the second app destroys the Mutex created by the first app immediately.


I'd have to wonder if that's part of the bug right there. Maybe when the mutex in the module goes out of scope, it calls the wrong code to destroy itself.

Do you get the same behaviour if you use a shared property within a class?


I'll try it and let you know.

I still haven't filed my feedback item yet. It may not be until Monday.


Top
 Profile  
Reply with quote  
 Post subject: Re: Location of Mutex Property and Resulting Effectiveness
PostPosted: Mon Mar 24, 2008 10:12 am 
Offline

Joined: Fri Sep 30, 2005 8:30 am
Posts: 254
kendoll wrote:
Do you get the same behaviour if you use a shared property within a class?


Yes, if I make the Mutex a shared property in a Class, the second app *still* destroys the mutex created by the first app when the second app Quits().

I'm pretty sure this is a bug, so I am going over to the feedback site and make a report.

It might very well be that storing the Mutex as a global app property is some undocumented requirement for Linux. At least, that seems to work fine.

I'll post the feedback item as soon as I'm finished.


Top
 Profile  
Reply with quote  
 Post subject: Re: Location of Mutex Property and Resulting Effectiveness
PostPosted: Mon Mar 24, 2008 10:38 am 
Offline

Joined: Fri Sep 30, 2005 8:30 am
Posts: 254
fitzbew wrote:
I'll post the feedback item as soon as I'm finished.


The feedback item is: http://www.realsoftware.com/feedback/lkrcfghy


Top
 Profile  
Reply with quote  
 Post subject: Re: Location of Mutex Property and Resulting Effectiveness
PostPosted: Fri May 08, 2009 7:55 am 
Offline
User avatar

Joined: Thu Nov 15, 2007 4:07 am
Posts: 313
Location: 't Zand, The Netherlands
Quote:
Quit() seems to be finishing ok, the problem is that the second app is destroying a mutex it did not create and only if the mutex is a Property in a module. If the mutex is a property in the App class, everything works according to design.
This might very well be a Linux bug. On Ubuntu 8.10 a second instance destroys the mutex even as a property of the App class.

Frank

_________________
Debian Sqeeze - Real Studio 2011r4
You have to have a little programming fun every day!


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 9 posts ] 

All times are UTC - 5 hours


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to:  
cron
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group