Where mutex is stored in windows

I want to know how mutex is working in process synchronization. Where these mutexes are stored in memory how another process know about this mutex?

If two different mutexes are having same name what will happen?
When you use an OS's API, the OS stores the mutex itself. You don't have to do anything with it.

Back in the days when we only had 1 core, the OS and all processes had to share it. The OS would start feeding instructions from a program into the processor and returning the output. However a processor could only do one task at a time. Since the OS and the other tasks still need to run, the OS would send an "interrupt" to the processor every so often to save the current state of the program and then start feeding instructions from another program.

When two processes wanted access to a resource (memory, hard-disk, network), the OS would handle the request by checking if that resource is already busy. If so, they "give a number" to that process and when that processes number comes up, they then have access to that resource. This is a semaphore (which is a kind of mutex). The OS doesn't do all of this automatically and often we need to make our own mutexes most of the time. This is done by simply telling the OS "this is a mutex", then "Can I aquire this mutex now please?" or "I'm done with it". The OS does the rest.

This prevents us from copying data from an array, getting interrupted half way through, then reading the rest of the array which doesn't correspond to the first part.

I'm fairly sure that if you have two mutexes with the same name, they will lock the same mutex. The mutex in memory is not part of your processes memory, it's in the OS. If you have a nice class which you use to handle mutexes, it's actually only a wrapper. The mutex will not disappear when the class goes out of scope (depending on what's in your destructor).
Last edited on
A mutex just puts a lock on a variable so that any threads trying to access it cannot do that until the current thread has finished with it and unlocked it. It is a useful thing to have when multi threading if your code involves accessing and changing the same variables by different threads. I'm assuming you know about multi threading and how they are not always synchronized in the way they all behave (if you use more than one thread). This is why mutexes are useful because they act as bouncer (for lack of better words) - only one thread accessing varaible at anytime and the thread has to have a password in order to do so.

READ MORE HERE: http://www.yolinux.com/TUTORIALS/LinuxTutorialPosixThreads.html#SYNCHRONIZATION

I don't think it is possible to have the same name for more than one mutex, just like any other variable, mutexes require unique names if you are going to be needing multiple of them.
Last edited on
Thanks for giving valuable information.

Mutex name is unique across current list of mutexes in a machine(WINDOWS PC) right?

Then what is the unique naming convention for not acquiring unknown process's mutex.
Tempted to say random word generator, but I think a good way to do it would be to use a variation of the name of the variable the mutex is holding. That way it is easier to recognize which mutex is guarding what
If you randomly generate mutex name then how can other process recognize/use this for synchronization?

I think it is hard coded by application name + some string.

Is it right or not?
It could be, I was only speculating when I said random word generator. But you could be right it could be what you suggested, so you have to ask people who program windows applications
Topic archived. No new replies allowed.