This is a very interesting article. I'd love to hear some feedback on this issue. The author references 'common language runtime', which I prefer to stay away from anyway!
http://blogs.microsoft.co.il/blogs/sash ... mutex.aspx
Locks vs. Mutex
- RichAlgeni
- Addict

- Posts: 935
- Joined: Wed Sep 22, 2010 1:50 am
- Location: Bradenton, FL
Re: Locks vs. Mutex
I think lock is the equivalent of a win32 critical section
the difference between a mutex vs critcal section is the scope Interprocess vs intraprocess
A critical section is a user owned lock to sync threads of the process, avoids context switches
A mutex is a kernel owned lock to provide interprocess synchronisation, requires context switches
I'm not sure what a PB Mutex is on windows without some digging.
the difference between a mutex vs critcal section is the scope Interprocess vs intraprocess
A critical section is a user owned lock to sync threads of the process, avoids context switches
A mutex is a kernel owned lock to provide interprocess synchronisation, requires context switches
I'm not sure what a PB Mutex is on windows without some digging.
Windows 11, Manjaro, Raspberry Pi OS


Re: Locks vs. Mutex
I think it's a critical section (not 100% sure). In fact I always found the name mutex confusingidle wrote: I'm not sure what a PB Mutex is on windows without some digging.
I believe CLR implement the Lock natively by itself. Again not 100% sure.
"Have you tried turning it off and on again ?"
Re: Locks vs. Mutex
Yes it most likely is a Critical Sectionluis wrote:I think it's a critical section (not 100% sure). In fact I always found the name mutex confusingidle wrote: I'm not sure what a PB Mutex is on windows without some digging.
I believe CLR implement the Lock natively by itself. Again not 100% sure.
and yes the CLR lock is a managed object from what I can tell and may even include monitoring to avoid deadlocks
A NumptyLock just what I need
Windows 11, Manjaro, Raspberry Pi OS


- RichAlgeni
- Addict

- Posts: 935
- Joined: Wed Sep 22, 2010 1:50 am
- Location: Bradenton, FL
Re: Locks vs. Mutex
The reason I was looking into this is that I am using a mutex to protect a map structure that contains file name, file length, expiration date, and a pointer to data. Since it's a structure in a map, I thought I should use a mutex, even when I am doing a 'FindMapElement'.
Is 'better safe than sorry' the correct course in this situation? Or should I look into using some for of a Lock?
Is 'better safe than sorry' the correct course in this situation? Or should I look into using some for of a Lock?
Re: Locks vs. Mutex
If you have cross thread access to the map then you should use a mutex
Windows 11, Manjaro, Raspberry Pi OS


- RichAlgeni
- Addict

- Posts: 935
- Joined: Wed Sep 22, 2010 1:50 am
- Location: Bradenton, FL
Re: Locks vs. Mutex
That's exactly what I am doing, using threads to access the map, with a Global mutex.
It seems to work great. So far I don't see any sort of resource hog issues occurring.
It seems to work great. So far I don't see any sort of resource hog issues occurring.
-
User_Russian
- Addict

- Posts: 1630
- Joined: Wed Nov 12, 2008 5:01 pm
- Location: Russia
Re: Locks vs. Mutex
In Windows-version PB, is used, the critical section, not mutex.idle wrote:I'm not sure what a PB Mutex is on windows without some digging.
But why is it called a mutex, is unclear.
Re: Locks vs. Mutex
If with mutex you mean a PB Mutex (CreateMutex()) is ok because actually it should be using a critical section and not an OS mutex, similarly to the desired course of action described in that article.RichAlgeni wrote:That's exactly what I am doing, using threads to access the map, with a Global mutex.
It seems to work great. So far I don't see any sort of resource hog issues occurring.
The problem is the PB object has been called Mutex, creating confusion with the CreateMutex_() API, and so when we talk about mutex here we should use the terms "PB Mutex" and "OS mutex" or we'll never be sure of what each other is talking about.
PB Mutex -> probably critical section -> threads only
OS mutex -> threads and different processes too (slower)
http://msdn.microsoft.com/en-us/library ... 85%29.aspx
"Have you tried turning it off and on again ?"
Re: Locks vs. Mutex
They both perform mutual exclusion so they are both technically mutex's but yes it's confusing when you're used to win32 api'sUser_Russian wrote:In Windows-version PB, is used, the critical section, not mutex.idle wrote:I'm not sure what a PB Mutex is on windows without some digging.
But why is it called a mutex, is unclear.
Maybe critical section just sounded to scary!
Windows 11, Manjaro, Raspberry Pi OS


