Click here to Skip to main content
14,577,302 members

Welcome to the Lounge

   

For discussing anything related to a software developer's life but is not for programming questions. Got a programming question?

The Lounge is rated Safe For Work. If you're about to post something inappropriate for a shared office environment, then don't post it. No ads, no abuse, and no programming questions. Trolling, (political, climate, religious or whatever) will result in your account being removed.
 
GeneralRe: Inkjet printers...there will never be a truce Pin
Peter R. Fletcher1-Jul-20 4:52
MemberPeter R. Fletcher1-Jul-20 4:52 
GeneralRe: Inkjet printers...there will never be a truce Pin
dandy723-Jul-20 5:16
Memberdandy723-Jul-20 5:16 
GeneralRe: Inkjet printers...there will never be a truce Pin
Peter R. Fletcher3-Jul-20 7:41
MemberPeter R. Fletcher3-Jul-20 7:41 
GeneralRe: Inkjet printers...there will never be a truce Pin
MikeMSA1-Jul-20 6:05
professionalMikeMSA1-Jul-20 6:05 
GeneralRe: Inkjet printers...there will never be a truce Pin
dandy723-Jul-20 5:20
Memberdandy723-Jul-20 5:20 
GeneralRe: Inkjet printers...there will never be a truce Pin
sasadler1-Jul-20 6:17
Membersasadler1-Jul-20 6:17 
GeneralRe: Inkjet printers...there will never be a truce Pin
AU_Steve1-Jul-20 19:43
MemberAU_Steve1-Jul-20 19:43 
GeneralSo this is weird... Pin
honey the codewitch30-Jun-20 4:25
mvahoney the codewitch30-Jun-20 4:25 
So I was fixing my Midi lib's streaming Send() routine to work with large sysex messages and generally be more efficient.

I get called back on send completion - from a different thread. However, list here is never touched again. I just hang on to the enumerator. The enumerator doesn't get touched outside the callback once its filled, and the callback never happens until its filled, so it's "safe" threadwise.

I need to keep the enumerator around so I have a member var called _sendQueue and to be safe I always do Interlocked operations when writing it.

Interlocked.Exchange(ref _sendQueue , list.GetEnumerator());


Anyway, the above succeeds, but a bit later when I'm packaging it for sending, I call _sendQueue.Current to get the current event and it returns null frome Current!!!

There are never nulls in that list I built.

I instead replaced the code above with this:

var e = list.GetEnumerator();
Interlocked.Exchange(ref _sendQueue , e);


And it works.Unsure | :~

For the life of me, I have no idea why. I'm about to dive into the IL out of curiosity but I don't think it's going to tell me much.

There have been a lot of oddities in writing this MIDI code, but the above takes the cake.
Real programmers use butterflies

GeneralRe: So this is weird... Pin
Richard Andrew x6430-Jun-20 4:29
professionalRichard Andrew x6430-Jun-20 4:29 
GeneralRe: So this is weird... Pin
honey the codewitch30-Jun-20 4:39
mvahoney the codewitch30-Jun-20 4:39 
GeneralRe: So this is weird... Pin
F-ES Sitecore30-Jun-20 6:25
mveF-ES Sitecore30-Jun-20 6:25 
GeneralRe: So this is weird... Pin
honey the codewitch30-Jun-20 7:08
mvahoney the codewitch30-Jun-20 7:08 
GeneralRe: So this is weird... Pin
F-ES Sitecore30-Jun-20 7:33
mveF-ES Sitecore30-Jun-20 7:33 
GeneralRe: So this is weird... Pin
honey the codewitch30-Jun-20 9:41
mvahoney the codewitch30-Jun-20 9:41 
GeneralRe: So this is weird... Pin
F-ES Sitecore1-Jul-20 1:37
mveF-ES Sitecore1-Jul-20 1:37 
GeneralRe: So this is weird... Pin
honey the codewitch1-Jul-20 4:04
mvahoney the codewitch1-Jul-20 4:04 
GeneralQuake Tower Pin
#realJSOP30-Jun-20 3:38
mva#realJSOP30-Jun-20 3:38 
GeneralRe: Quake Tower Pin
dandy7230-Jun-20 3:46
Memberdandy7230-Jun-20 3:46 
GeneralRe: Quake Tower Pin
OriginalGriff30-Jun-20 3:53
mveOriginalGriff30-Jun-20 3:53 
GeneralRe: Quake Tower Pin
#realJSOP30-Jun-20 5:14
mva#realJSOP30-Jun-20 5:14 
GeneralRe: Quake Tower Pin
dandy7230-Jun-20 6:41
Memberdandy7230-Jun-20 6:41 
PraiseRe: Quake Tower Pin
Slacker00730-Jun-20 4:00
professionalSlacker00730-Jun-20 4:00 
GeneralRe: Quake Tower Pin
Kris Lantz30-Jun-20 4:15
professionalKris Lantz30-Jun-20 4:15 
GeneralI'm Going To Take A Hostage PinPopular
MadGerbil30-Jun-20 2:21
MemberMadGerbil30-Jun-20 2:21 
GeneralRe: I'm Going To Take A Hostage Pin
W Balboos, GHB30-Jun-20 2:27
mveW Balboos, GHB30-Jun-20 2:27 

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.