Click here to Skip to main content
15,922,894 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.

 
QuestionThis is driving me round the twist. Pin
OriginalGriff14-Sep-19 9:42
mveOriginalGriff14-Sep-19 9:42 
AnswerRe: This is driving me round the twist. Pin
David O'Neil14-Sep-19 19:20
professionalDavid O'Neil14-Sep-19 19:20 
AnswerRe: This is driving me round the twist. Pin
David O'Neil14-Sep-19 19:27
professionalDavid O'Neil14-Sep-19 19:27 
Generalif you hate writing and trying to test multithreaded code raise your hand Pin
honey the codewitch14-Sep-19 9:41
mvahoney the codewitch14-Sep-19 9:41 
GeneralRe: if you hate writing and trying to test multithreaded code raise your hand Pin
Greg Utas14-Sep-19 13:14
professionalGreg Utas14-Sep-19 13:14 
GeneralRe: if you hate writing and trying to test multithreaded code raise your hand Pin
honey the codewitch14-Sep-19 13:16
mvahoney the codewitch14-Sep-19 13:16 
GeneralRe: if you hate writing and trying to test multithreaded code raise your hand Pin
Greg Utas14-Sep-19 13:46
professionalGreg Utas14-Sep-19 13:46 
GeneralRe: if you hate writing and trying to test multithreaded code raise your hand Pin
honey the codewitch14-Sep-19 13:51
mvahoney the codewitch14-Sep-19 13:51 
Greg Utas wrote:
Yes, I'm a big fan of cooperative threading. I haven't worked in C#, but I'd guess that yield() does the same thing as what I call Pause() in my code.


Probably "inside out" of what you're thinking.

Assuming you call Pause() while inside a loop or something to yield time.

yield however, is entirely different. It builds state machines for you to break apart the routine.

Hence

C#
IEnumerable<string> Test() {
   yield return "dog";
   yield return "cat";
   yield return "mouse";
}
...
foreach(var item in Test())
   Console.WriteLine(item);

yields
dog
cat
mouse

each time it encounters a yield return it returns from the function. The next time the function is called essentially it will start after that yield return statement at the next line.

This voodoo is accomplished using a state machine the compiler builds for you.

So each time the routine is called, it knows what state it's in and can execute the next instruction.

So in your cooperative multithreading code. you'd just loop over whatever you needed to loop over, and time is returned to your function because the yield return dropped you out of the function in the "middle of the call"

it's a lot easier to use than to explain, but it helps if you have familiarity with the concept of a coroutine first.
When I was growin' up, I was the smartest kid I knew. Maybe that was just because I didn't know that many kids. All I know is now I feel the opposite.

GeneralRe: if you hate writing and trying to test multithreaded code raise your hand Pin
Greg Utas14-Sep-19 15:03
professionalGreg Utas14-Sep-19 15:03 
GeneralRe: if you hate writing and trying to test multithreaded code raise your hand Pin
honey the codewitch14-Sep-19 15:07
mvahoney the codewitch14-Sep-19 15:07 
GeneralRe: if you hate writing and trying to test multithreaded code raise your hand Pin
Greg Utas14-Sep-19 15:23
professionalGreg Utas14-Sep-19 15:23 
GeneralRe: if you hate writing and trying to test multithreaded code raise your hand Pin
honey the codewitch14-Sep-19 15:25
mvahoney the codewitch14-Sep-19 15:25 
GeneralRe: if you hate writing and trying to test multithreaded code raise your hand Pin
Nand3214-Sep-19 17:01
Nand3214-Sep-19 17:01 
GeneralRe: if you hate writing and trying to test multithreaded code raise your hand Pin
Munchies_Matt14-Sep-19 22:40
Munchies_Matt14-Sep-19 22:40 
GeneralRe: if you hate writing and trying to test multithreaded code raise your hand Pin
honey the codewitch15-Sep-19 3:32
mvahoney the codewitch15-Sep-19 3:32 
GeneralRe: if you hate writing and trying to test multithreaded code raise your hand Pin
Richard Deeming15-Sep-19 23:52
mveRichard Deeming15-Sep-19 23:52 
GeneralRe: if you hate writing and trying to test multithreaded code raise your hand Pin
honey the codewitch16-Sep-19 0:31
mvahoney the codewitch16-Sep-19 0:31 
GeneralFinally an AI that solves REAL problems! Pin
Sander Rossel14-Sep-19 9:33
professionalSander Rossel14-Sep-19 9:33 
GeneralRe: Finally an AI that solves REAL problems! Pin
Mycroft Holmes14-Sep-19 13:02
professionalMycroft Holmes14-Sep-19 13:02 
GeneralSous Vide everything Pin
Jörgen Andersson14-Sep-19 8:51
professionalJörgen Andersson14-Sep-19 8:51 
GeneralRe: Sous Vide everything Pin
honey the codewitch14-Sep-19 9:43
mvahoney the codewitch14-Sep-19 9:43 
GeneralRe: Sous Vide everything Pin
OriginalGriff14-Sep-19 9:45
mveOriginalGriff14-Sep-19 9:45 
GeneralRe: Sous Vide everything Pin
Jörgen Andersson14-Sep-19 9:48
professionalJörgen Andersson14-Sep-19 9:48 
GeneralRe: Sous Vide everything Pin
OriginalGriff14-Sep-19 10:02
mveOriginalGriff14-Sep-19 10:02 
GeneralRe: Sous Vide everything Pin
Jörgen Andersson14-Sep-19 10:06
professionalJörgen Andersson14-Sep-19 10:06 

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.