|
James Curran wrote: Most embedded systems still have a "power" switch, which is not hard-wired to the power, but instead, starts the "power-down" procedure What do you plan to to in this omnipresent "power-down" procedure when there is nothing to save or cleanup? If your code runs multiple threads, each executiong an infinite loop (which is quite common in embedded code), will you broadcast a 'power-down' message to each of these loops and let them all take various terminating actions? Conceptually, almost all interrupt handlers are infinite loops, making another iteration when an interrupt is received. Will you signal the 'power-down' to each handler as well, for them to do their termination handling?
If there are cleanup actions to be done for one, or possibly a couple, of the threads, you should of course send these theads a termination request for orderly shutdown. But lots of embedded threads, or even complete embedded systems, have no cleanup requirements. They have no need for any 'shutting down' signal, but can be cut off without formalities, just like when power disappears.
The CHILL language was specifically designed for embedded systems (specifically: phone switches), and it provided an explicit loop mechanism: 'for ever do ...'. Phone switches are also illustrating that the system as a whole is designed for never terminating. If a phone switch stops running, it is due to an error or other exceptional condition; the code design assumes perpetual running.
|
|
|
|
|
I once wrote the following code:
var HellFreezesOver = false
do until(HellFreezesOver)
// code
loop
The language I was working in didn't have the concept of an infinite loop and I needed one for this application. Of course, the application terminated when the Red Sox won the World Series in 2004.
|
|
|
|
|
My variant of the same was "WW3".
|
|
|
|
|
READY.
10 PRINT "HELLO"
20 GOTO 10
RUN
|
|
|
|
|
A question from a CP user last night involved how he should go about making a portion of an app multithreaded.
So I helped him through it at least somewhat.
After that I find out he doesn't know how to spin a loop with no ending condition in C#. while(true) {}
And now I feel like a gave a child a loaded pistol
Real programmers use butterflies
|
|
|
|
|
Yeah ... I get the feeling that one has lied his way into a job he has no idea how to do and is desperately trying to cover up his ignorance. His comments aren't confidence inspiring.
"I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
"Common sense is so rare these days, it should be classified as a super power" - Random T-shirt
AntiTwitter: @DalekDave is now a follower!
|
|
|
|
|
Now he should be able to shoot himself in the foot multiple times, from multiple threads.
Tomorrow his questions will be about Thread Starvation and Deadlock, but all he will know is that the UI is frozen.
"Time flies like an arrow. Fruit flies like a banana."
|
|
|
|
|
while (true)
{
new Thread(() =>
{
}).Start();
} Am I doing this right?
|
|
|
|
|
I'd come after you for that. You're not the only one with a pitchfork - I collect them from villagers.
Real programmers use butterflies
|
|
|
|
|
Alright, how about I optimize that using the faster and lightweight TPL?
Lightweight threads from the threadpool, or, if possible, just time slice and save the overhead from starting up a new thread altogether!
while (true)
{
Task.Factory.StartNew(() => {
});
} All fixed
|
|
|
|
|
Unless you need to pass in a custom scheduler or something like that you really should use Task.Run()
While TaskFactory.StartNew() isn't obsolete or anything, the overload you're using has been supplanted by Task.Run()
I think I read that from Stephen Toub, but it could have been someone else at the Microsoft blogs.
Just sayin'
*hides*
Real programmers use butterflies
|
|
|
|
|
I actually always use Task.Start except for the very beginning when TPL was hot and happening.
It's just that I don't have a lot of need for it anymore and it's been a while since I last used it.
I had to Google and TaskFactory.StartNew was the first one that came up.
However, none of that matters with the while(true) still in place
|
|
|
|
|
i think you mean Task.Run()
But yeah,although if you really want to be obnoxious you do
while(true) {
new Thread(()=> { while(true); }).Start();
}
So it chokes the scheduler
Real programmers use butterflies
|
|
|
|
|
|
If you ever manage actual endless recursion on a Linear Bounded Automata (like a computer) you will have solved several undecidable computer science problems and opened up a huge can of worms to boot.
I'd pay for front row seats to that.
If however, you simply want a stack overflow exception, I can work with that too.
Real programmers use butterflies
|
|
|
|
|
Isn't that what functional languages do?
Well, not really, since they compile to while loops, but the effect is the same
|
|
|
|
|
Sander Rossel wrote: Can we put some endless recursion in there too? As long as it is not an endless discussion...
M.D.V.
If something has a solution... Why do we have to worry about?. If it has no solution... For what reason do we have to worry about?
Help me to understand what I'm saying, and I'll explain it better to you
Rating helpful answers is nice, but saying thanks can be even nicer.
|
|
|
|
|
public void Discuss(bool myOpinion, bool otherOpinion)
{
if (myOpinion == otherOpinion)
{
myOpinion != myOpinion;
}
else
{
otherOpinion = myOpinion;
}
Discuss(myOpinion, otherOpinion);
}
|
|
|
|
|
Agreed, because this system shouldn't waste time before crashing.
|
|
|
|
|
I just want the crashing code to follow Microsoft guidelines and best practices.
Real programmers use butterflies
|
|
|
|
|
Don't tell me you have started to work for the WinUpdates team...
M.D.V.
If something has a solution... Why do we have to worry about?. If it has no solution... For what reason do we have to worry about?
Help me to understand what I'm saying, and I'll explain it better to you
Rating helpful answers is nice, but saying thanks can be even nicer.
|
|
|
|
|
Needs some recursion. Too understandable as-is. Maybe call this from within the instantiated threads. Yeah, that's it!
|
|
|
|
|
let's just skip right to Stack::Blow();
"They have a consciousness, they have a life, they have a soul! Damn you! Let the rabbits wear glasses! Save our brothers! Can I get an amen?"
|
|
|
|
|
Computers need stress tested every once in a while!
|
|
|
|
|
Just tell your computer "we need to talk"
|
|
|
|