Click here to Skip to main content
15,925,400 members
Home / Discussions / C#
   

C#

 
AnswerRe: Text Encoding Pin
if_mel_yes_else_no30-Aug-05 9:40
if_mel_yes_else_no30-Aug-05 9:40 
GeneralRe: Text Encoding Pin
Guinness4Strength30-Aug-05 9:51
Guinness4Strength30-Aug-05 9:51 
Questionregex Pin
surfman1930-Aug-05 9:04
surfman1930-Aug-05 9:04 
AnswerRe: regex Pin
Guffa30-Aug-05 9:16
Guffa30-Aug-05 9:16 
General[Message Deleted] Pin
surfman1930-Aug-05 9:24
surfman1930-Aug-05 9:24 
GeneralRe: regex Pin
surfman1930-Aug-05 9:28
surfman1930-Aug-05 9:28 
GeneralRe: regex Pin
User 665830-Aug-05 10:18
User 665830-Aug-05 10:18 
GeneralRe: regex Pin
Susan Hernandez31-Aug-05 15:31
Susan Hernandez31-Aug-05 15:31 
Questionforeach DataSet Pin
samoore30-Aug-05 6:19
samoore30-Aug-05 6:19 
QuestionRe: foreach DataSet Pin
Guffa30-Aug-05 8:29
Guffa30-Aug-05 8:29 
AnswerRe: foreach DataSet Pin
samoore30-Aug-05 9:31
samoore30-Aug-05 9:31 
QuestionCustom Sinks Pin
esjq30-Aug-05 5:58
esjq30-Aug-05 5:58 
AnswerRe: Custom Sinks Pin
esjq30-Aug-05 21:37
esjq30-Aug-05 21:37 
QuestionTransparency not just in forms Pin
if_mel_yes_else_no30-Aug-05 5:57
if_mel_yes_else_no30-Aug-05 5:57 
QuestionInstalling application using C# Pin
Samar Aarkotti30-Aug-05 5:53
Samar Aarkotti30-Aug-05 5:53 
AnswerRe: Installing application using C# Pin
Guinness4Strength30-Aug-05 9:31
Guinness4Strength30-Aug-05 9:31 
GeneralRe: Installing application using C# Pin
Anonymous30-Aug-05 12:19
Anonymous30-Aug-05 12:19 
GeneralRe: Installing application using C# Pin
Guinness4Strength31-Aug-05 3:54
Guinness4Strength31-Aug-05 3:54 
QuestionQuestion about Mutex Pin
Alex Cutovoi30-Aug-05 5:17
Alex Cutovoi30-Aug-05 5:17 
AnswerRe: Question about Mutex Pin
Andy Brummer30-Aug-05 8:15
sitebuilderAndy Brummer30-Aug-05 8:15 
GeneralRe: Question about Mutex Pin
Alex Cutovoi30-Aug-05 9:25
Alex Cutovoi30-Aug-05 9:25 
GeneralRe: Question about Mutex Pin
Andy Brummer30-Aug-05 10:30
sitebuilderAndy Brummer30-Aug-05 10:30 
GeneralRe: Question about Mutex Pin
Alex Cutovoi30-Aug-05 14:17
Alex Cutovoi30-Aug-05 14:17 
GeneralRe: Question about Mutex Pin
Andy Brummer30-Aug-05 19:30
sitebuilderAndy Brummer30-Aug-05 19:30 
Imagine the mutex as a counter.
When you call WaitOne and the counter is zero then it is incremented.
If the counter is one then WaitOne enters a loop until the counter is decreased to zero and then it is incremented to 1 and the function returns.

Whenever WaitOne returns the counter is in a one state.

ReleaseMutex decrements the counter to 0.
If no threads are in WaitOne then nothing happens, but if there is a thread executing waitOne it bumps the counter back to 1 and then continues on.

That is the simplest conceptual model of a mutex. In windows terminology that is a single count semaphore which is sometimes called a mutex in other operating systems.

In windows and .net the mutex keeps track of which thread owns it. Imagine this as a counter plus a field for the threadID of the owning thread. That's how your sample worked. When each thread went out of scope all mutexes with that flag set to the threadID were released, which allowed other threads executing WaitOne to return. A thread owns the mutex when it exits from WaitOne because the mutex structure is locked and the threadID of the owner is recorded. Also through the magic of the thread scheduler, threads executing WaitOne are suspended and one is selected to wake up when releaseMutex is called rather then looping indefinitely.


I can imagine the sinking feeling one would have after ordering my book,
only to find a laughably ridiculous theory with demented logic once the book arrives - Mark McCutcheon

GeneralRe: Question about Mutex Pin
Alex Cutovoi31-Aug-05 2:53
Alex Cutovoi31-Aug-05 2:53 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.