Click here to Skip to main content
15,915,328 members
Home / Discussions / C#
   

C#

 
GeneralRe: foreach Dictionary Pin
The Nightcoder2-Jun-08 2:20
The Nightcoder2-Jun-08 2:20 
GeneralRe: foreach Dictionary Pin
George_George3-Jun-08 2:36
George_George3-Jun-08 2:36 
GeneralRe: foreach Dictionary Pin
supercat96-Nov-08 9:12
supercat96-Nov-08 9:12 
GeneralRe: foreach Dictionary Pin
The Nightcoder28-May-08 22:01
The Nightcoder28-May-08 22:01 
Questionatomic operation of reference assignment? Pin
George_George27-May-08 3:40
George_George27-May-08 3:40 
AnswerRe: atomic operation of reference assignment? Pin
Guffa27-May-08 4:30
Guffa27-May-08 4:30 
GeneralRe: atomic operation of reference assignment? Pin
George_George27-May-08 23:54
George_George27-May-08 23:54 
GeneralRe: atomic operation of reference assignment? Pin
supercat910-Jul-08 7:07
supercat910-Jul-08 7:07 
Guffa wrote:
Yes, assigning a reference is an atomic operation.


DANGER WILL ROBINSON! DANGER WILL ROBINSON!

An assignment of a reference type consists of an atomic read followed by an atomic write. The assignment as a whole is not atomic.
Assume var2 starts == 1.

Thread 1:
  var1 = var2;

Thread2:
  var2 = 2;
  var1 = 3;
If assignments were atomic, var1 might end up equal to 2 or 3, but it could not possibly end up equal to anything else (such as 1). Since they are not atomic, however, thead 1 decomposes as "temp = var2; var1 = temp;". The operations could thus be sequenced as "temp = var2 [1]; var2 = 2; var1 = 3; var1 = temp [1];"

It would be possible to write a generic class to support true atomic assignments. Given the existence of Interlocked.CompareExchange it could even be done without locks or spin-waits(*) in such a way that the total time required for any number of operations would be bounded (the time required for any particular operation would only be bounded if the number of other operations was limited).

(*) A thread may have to retry an operation up to 'n' times if other threads perform 'n' operations during its execution; it is never necessary, however, for a thread to wait for another thread to do something.

I don't know if there are any nice algorithms to synthesize atomic assignment given atomic compare-and-exchange. The best lock-free approach I can come up with is pretty nasty, but it would work.
AnswerRe: atomic operation of reference assignment? Pin
Guffa10-Jul-08 16:15
Guffa10-Jul-08 16:15 
GeneralRe: atomic operation of reference assignment? Pin
supercat910-Jul-08 18:21
supercat910-Jul-08 18:21 
AnswerRe: atomic operation of reference assignment? Pin
Zoltan Balazs27-May-08 4:46
Zoltan Balazs27-May-08 4:46 
GeneralRe: atomic operation of reference assignment? Pin
George_George27-May-08 23:55
George_George27-May-08 23:55 
QuestionHow to keep track of background threads? Pin
ptr2void27-May-08 3:09
ptr2void27-May-08 3:09 
AnswerRe: How to keep track of background threads? Pin
N a v a n e e t h27-May-08 3:12
N a v a n e e t h27-May-08 3:12 
GeneralRe: How to keep track of background threads? Pin
ptr2void27-May-08 3:15
ptr2void27-May-08 3:15 
GeneralRe: How to keep track of background threads? Pin
N a v a n e e t h27-May-08 3:18
N a v a n e e t h27-May-08 3:18 
GeneralRe: How to keep track of background threads? Pin
ptr2void27-May-08 3:24
ptr2void27-May-08 3:24 
GeneralRe: How to keep track of background threads? Pin
N a v a n e e t h27-May-08 3:41
N a v a n e e t h27-May-08 3:41 
GeneralRe: How to keep track of background threads? Pin
ptr2void27-May-08 3:52
ptr2void27-May-08 3:52 
GeneralRe: How to keep track of background threads? Pin
supercat912-Jul-08 12:21
supercat912-Jul-08 12:21 
QuestionWord Plug-in eventhandlers stops working... Pin
Anders Molin27-May-08 3:00
professionalAnders Molin27-May-08 3:00 
QuestionSetting values for anonymous types Pin
Yoyosch27-May-08 2:34
Yoyosch27-May-08 2:34 
AnswerRe: Setting values for anonymous types Pin
Colin Angus Mackay27-May-08 3:13
Colin Angus Mackay27-May-08 3:13 
QuestionHow to block popups in broswer component? Pin
asma_panjabi27-May-08 2:14
asma_panjabi27-May-08 2:14 
AnswerRe: How to block popups in broswer component? Pin
buchstaben27-May-08 5:22
buchstaben27-May-08 5:22 

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.