Click here to Skip to main content
15,910,787 members
Home / Discussions / C#
   

C#

 
AnswerRe: Does Boolean not need an Interlocked.Exchange method? Pin
Christian Graus20-Aug-08 15:47
protectorChristian Graus20-Aug-08 15:47 
GeneralRe: Does Boolean not need an Interlocked.Exchange method? Pin
JoeRip20-Aug-08 15:52
JoeRip20-Aug-08 15:52 
GeneralRe: Does Boolean not need an Interlocked.Exchange method? Pin
Mark Churchill20-Aug-08 17:53
Mark Churchill20-Aug-08 17:53 
GeneralRe: Does Boolean not need an Interlocked.Exchange method? Pin
JoeRip20-Aug-08 18:08
JoeRip20-Aug-08 18:08 
GeneralRe: Does Boolean not need an Interlocked.Exchange method? Pin
Christian Graus20-Aug-08 19:36
protectorChristian Graus20-Aug-08 19:36 
GeneralRe: Does Boolean not need an Interlocked.Exchange method? Pin
N a v a n e e t h20-Aug-08 20:28
N a v a n e e t h20-Aug-08 20:28 
GeneralRe: Does Boolean not need an Interlocked.Exchange method? Pin
Mark Churchill21-Aug-08 5:31
Mark Churchill21-Aug-08 5:31 
AnswerRe: Does Boolean not need an Interlocked.Exchange method? Pin
Daniel Grunwald21-Aug-08 0:45
Daniel Grunwald21-Aug-08 0:45 
Access to all primitive types <=32 bit is atomic.
So reading and writing ints and bools is safe. But a "read-modify-write" operation is not atomic; so for integers, there's Interlocked.Increment etc.
Now, the only kind of "read-modify-write" I could image for bools is negating them. That's not safe.
But something like "if (!a) { a = true; }" is safe: if another thread happens to change the value between the "if (!a)" and the "a = true;", the only thing it can have done is setting a to true - but that's not going cause any problems, since we are about to set a to true anyway.

However, if you use the boolean for things like "run this code only once", then you have to lock/use Interlocked.CompareExchange to ensure that only the first thread to set the boolean to true runs the "run only once" code.

Remember that usually, there's no point in making all members of a class thread-safe, as combined operations need locking anyways, so the user of a class usually has to do his own locking.
E.g. given a thread-safe list, "if (!list.Contains(x)) list.Add(x);" is not thread-safe, so you need to "lock (list)" around every list access - but if you have to lock around every access, you could as well start with a non-thread-safe list.
GeneralRe: Does Boolean not need an Interlocked.Exchange method? Pin
JoeRip21-Aug-08 2:31
JoeRip21-Aug-08 2:31 
GeneralRe: Does Boolean not need an Interlocked.Exchange method? Pin
Daniel Grunwald21-Aug-08 2:39
Daniel Grunwald21-Aug-08 2:39 
Questionftp server - client question here Pin
AndreasAlex20-Aug-08 14:56
AndreasAlex20-Aug-08 14:56 
AnswerRe: ftp server - client question here Pin
AndreasAlex20-Aug-08 14:59
AndreasAlex20-Aug-08 14:59 
QuestionHow to programatically manipulate forms authentication settings of web.config file Pin
tjkota20-Aug-08 11:46
tjkota20-Aug-08 11:46 
AnswerRe: How to programatically manipulate forms authentication settings of web.config file Pin
Christian Graus20-Aug-08 15:49
protectorChristian Graus20-Aug-08 15:49 
QuestionCreated Web Proxy but can't return images..C# Pin
DeepToot20-Aug-08 9:20
DeepToot20-Aug-08 9:20 
AnswerRe: Created Web Proxy but can't return images..C# Pin
DeepToot21-Aug-08 4:11
DeepToot21-Aug-08 4:11 
QuestionMDI; Finding a property on parent from MDI child form Pin
ianhunt0120-Aug-08 9:02
ianhunt0120-Aug-08 9:02 
AnswerRe: MDI; Finding a property on parent from MDI child form Pin
Mark Miller20-Aug-08 9:32
Mark Miller20-Aug-08 9:32 
GeneralRe: MDI; Finding a property on parent from MDI child form Pin
ianhunt0120-Aug-08 20:18
ianhunt0120-Aug-08 20:18 
GeneralRe: MDI; Finding a property on parent from MDI child form Pin
Mark Miller21-Aug-08 9:44
Mark Miller21-Aug-08 9:44 
GeneralRe: MDI; Finding a property on parent from MDI child form Pin
ianhunt0121-Aug-08 21:22
ianhunt0121-Aug-08 21:22 
GeneralRe: MDI; Finding a property on parent from MDI child form Pin
Mark Miller23-Aug-08 14:46
Mark Miller23-Aug-08 14:46 
GeneralRe: MDI; Finding a property on parent from MDI child form Pin
ianhunt0124-Aug-08 21:15
ianhunt0124-Aug-08 21:15 
AnswerRe: MDI; Finding a property on parent from MDI child form Pin
led mike20-Aug-08 9:33
led mike20-Aug-08 9:33 
GeneralRe: MDI; Finding a property on parent from MDI child form Pin
ianhunt0120-Aug-08 20:16
ianhunt0120-Aug-08 20:16 

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.