473,396 Members | 2,010 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Forcibly destroy a mutex.

UJ
Is there any way to forcibly destroy a mutex?

Let's suppose I have a log file that I'm writing to. I have code in the
write that creates a mutex. But some program somewhere hasn't released it
yet. So after waiting a while (5 seconds let's say) I write to the file
anyway. (I figure it can't have taken that long.)

Problem is, the next time I try to write to the log file, I have to wait
that same 5 seconds because the mutex is still around. But I don't want
everybody waiting for it.

Is there any way to delete the mutex when you don't own it?

TIA - Jeff.
Jul 10 '06 #1
3 3729
Hi,
Are you using System.Threading.Mutex ?

If you have mutexes around several process you can continue with the
execution using WaitAny, therefore if you own of the threads that you try to
synchronize (that's the purpose of the mutex) and you have finish the mutex
will continue the execution as "WaitAny" will allow you to execute when at
least one of the subscribed mutexes has finished.

Maybe you meant monitors or reader/writer locks.

--
Salvador Alvarez Patuel
Exony Ltd - London, UK
"UJ" wrote:
Is there any way to forcibly destroy a mutex?

Let's suppose I have a log file that I'm writing to. I have code in the
write that creates a mutex. But some program somewhere hasn't released it
yet. So after waiting a while (5 seconds let's say) I write to the file
anyway. (I figure it can't have taken that long.)

Problem is, the next time I try to write to the log file, I have to wait
that same 5 seconds because the mutex is still around. But I don't want
everybody waiting for it.

Is there any way to delete the mutex when you don't own it?

TIA - Jeff.
Jul 10 '06 #2
UJ wrote:
Problem is, the next time I try to write to the log file, I have to wait
that same 5 seconds because the mutex is still around. But I don't want
everybody waiting for it.
Maybe your program could just remember that the mutex is invalid and
ignore it the next time it needs to write to the file? So each process
will only wait the 5 secs once.

Anyway, the only clean solution would be to fix the program that doesn't
release the mutex!
Is there any way to delete the mutex when you don't own it?
None that I know of without checking the docs.. :)

hth,
Max
Jul 10 '06 #3
UJ wrote:
Is there any way to forcibly destroy a mutex?

Let's suppose I have a log file that I'm writing to. I have code in the
write that creates a mutex. But some program somewhere hasn't released it
yet. So after waiting a while (5 seconds let's say) I write to the file
anyway. (I figure it can't have taken that long.)
What do you mean by "creates a mutex"? Instantiates a new mutex? Gains
ownership?

If the latter, there's nothing you can do. It's what mutexes are for,
ensure safe access to the resource without other threads intervening.

If the former, I can't see how a mutex would work at all.

If the amount of time to write your logmessage takes that long, you're
probably better of with a producer/consumer queue (and scrutinizing why
on earth it takes that long might also be in order). Queue any message
you want to log, and have a dedicated thread dequeue them to write them
to their destination.

--
Willem van Rumpt
Jul 10 '06 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Srijit Kumar Bhadra | last post by:
Hello, Here is some sample code with pywin32 build 203 and ctypes 0.9.6. Best regards, /Srijit File: SharedMemCreate_Mutex_win32all.py # This application should be used with...
5
by: Ken Varn | last post by:
I have a named mutex object that is accessed by both an asp.net application and a Windows executable .net application. The Windows executable runs under the administrator logon, while the asp.net...
2
by: Ken Durden | last post by:
I'm setting up an interface where clients must perform external locking before calling certain commands. I do this to force them to specify the duration the action they performed must persist...
193
by: Michael B. | last post by:
I was just thinking about this, specifically wondering if there's any features that the C specification currently lacks, and which may be included in some future standardization. Of course, I...
2
by: Martin Maat | last post by:
Hi. I want to use the same mutex in different classes (web pages in an ASP.NET application). In global.asax.cs, the class that starts up first, I create a Mutex like this: static private...
16
by: Ed Sutton | last post by:
I use a mutex to disallow starting a second application instance. This did not work in a release build until I made it static member of my MainForm class. In a debug build, first instance got...
2
by: tony.newsgrps | last post by:
Hi there, I'm trying to understand the impact of killing a process that owns a system mutex (used to ensure there is only 1 instance of my program running) Here is my code pretty much: try...
3
by: NaeiKinDus | last post by:
Hello, i'm trying to program a thread that would be locked (by a mutex) and that would only be unlocked once that a function (generating data) is done. The purpose is to generate data, and unlock...
11
by: Lamont Sanford | last post by:
Given an object of type Mutex, what method or property should be called to determine if it is currently owned? I could call WaitOne(0,false) -- and if the return value is false, I could deduce...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.