Hello, I looked through such concepts as Mutex, Semaphore, SemaphoreSlim, AutoResentEvent, etc. During the proceedings with them such questions arose:
1) If you donβt give Mutex a name, it turns out that it starts working like a normal lock, does synchronization between threads is at the level of a single process, and interprocess synchronization disappears? That is, in such cases it is no different from lock?
2) A question similar to the previous one, Semaphore without specifying a name, it turns into an ordinary loc only with support for synchronization of several streams, well, it is understandable here. Then it turns out from SemaphoreSlim it differs only in more complex creation because Semaphore (without a name) is created at the kernel level and as a result (due to the lack of a name) it works only for one process (that is, the sense that it is created at levels there is no kernel). So it turns out that SemaphoreSlim and Semaphore (without a name) will work the same way, except that the first is a little faster. Do I understand the alignment correctly? Or is there any difference?
- 2And what have the core of the OS? :-) - Vladimir Martyanov
- Well, as I understand it, the area of ββthe code, access to which is synchronized using Mutex, is located in the Windows memory. Not inside the managed heap that the CLR has requested from Windows. And access to this area is through the core. Well, I may be wrong) - Snuppi
- In any case, I rename the topic) - Snuppi
- With the help of Mutex, you can synchronize not only access to the code :-) - Vladimir Martyanov
- Hmm, do not quite understand what you mean. If you have a type of synchronization of access to any file, then this is the same code, just a code to write data to a file, for example) We are talking about ordinary C # code, the code is placed between the WaitOne () and Release () methods. As a result, this code becomes a shared resource, access to which is carried out - Snuppi
|
1 answer
Yes, the meaning of the unnamed Mutex is practically the same as lock through
lock. The difference is thatlockdoes not work acrossAppDomainboundaries, and the unnamedMutexis available throughout the process.MutexisWaitHandle'om, that is, you can, for example, wait for it with a timeout or wait for one of severalMutex's to be blocked.lockimplemented better thanMutex.
The difference between
SemaphoreandSemaphoreSlimabout the same.Semaphore- wrapper over a Win32 object.SemaphoreSlimsignificantly faster, but it works only inside the process and does not exportWaitHandle.
- oneThe phrase
Mutex ΡΠ²Π»ΡΠ΅ΡΡΡ WaitHandle'ΠΎΠΌ, ΡΠΎ Π΅ΡΡΡ Π²Ρ ΠΌΠΎΠΆΠ΅ΡΠ΅ ΠΏΠΎΠ»ΡΠ·ΠΎΠ²Π°ΡΡ, Π½Π°ΠΏΡΠΈΠΌΠ΅Ρ, Π΄ΠΎΠΆΠΈΠ΄Π°ΡΡΡΡ Π΅Π³ΠΎ Ρ ΡΠ°ΠΉΠΌΠ°ΡΡΠΎΠΌ ΠΈΠ»ΠΈ ΠΆΠ΄Π°ΡΡ Π±Π»ΠΎΠΊΠΈΡΠΎΠ²ΠΊΠΈ ΠΎΠ΄Π½ΠΎΠ³ΠΎ ΠΈΠ· Π½Π΅ΡΠΊΠΎΠ»ΡΠΊΠΈΡ Mutex'ΠΎΠ².incomprehensible, correct, please - Andrey NOP - @Andrey: Yeah, fixed it, thanks! - VladD
|