| « Prev | Page 1 | Page 2 | Next » |
|
Welcome Mr. Chen. You can always tell a guy's first day on the job. This WTF is in early! |
Re: Raymond Chen on Sleep() Deprivation
2006-09-11 12:27
•
by
Puckdropper
|
|
He's very punctual too. Every day at 7:00 AM exactly, his time, there's a new blog post. ; - )
|
|
Alex must be Sleep()ing in right now. |
Earliest Daily WTF posting ever and entered extactly at 12.00 pm. Something tells me that Raymond is using his automatic posting script he uses for his own blog for this one also. See if tomorrows post will be posted at 12.00 pm as well. http://blogs.msdn.com/oldnewthing/archive/2004/02/19/76369.aspx
|
Re: Raymond Chen on Sleep() Deprivation
2006-09-11 12:42
•
by
ammoQ
|
|
Since Alex is on vacation this week, the main forum is fed by an auto-pilot script. Stay tuned, folks, we'll see contributions from a lot of very interesting guest authors this week.
|
|
...wait a minute....
|
|
Regarding "The Daily WTF Reader Survey (tm)", can anyone tell me the difference between a "Programmer/Developer I" and a "Programmer/Developer IV"... just so I can decide which I am! Oh, and assuming this survey is being used to decide what types of advertising we get on the site, what do people reckon I should choose to get more table football/beanbag girl type ad's? :-) |
Re: Raymond Chen on Sleep() Deprivation
2006-09-11 13:02
•
by
merreborn
|
|
Classic WTF: reinventing the wheel in the stupidest way possible.
|
|
Actually this idiom is neither uncommon nor invalid on platforms that lack a directly-coded sleep() equivalent, and I'll bet the programmer came from such an environment. That's no excuse for doing absolutely nothing in the error cases, though, and having it exit the thread is just WTF, but the basic idea isn't crazy.
|
Re: Raymond Chen on Sleep() Deprivation
2006-09-11 13:05
•
by
Anonymous
|
Programmer/Developer I would basically be a guy with less experience who handles the less complex tasks, and a P/D IV would be akin to a senior developer or technical lead in my opinion -- the go-to guy with the knowledge, experience, and (usually) can help you if you're having a problem. That is, those that don't end up on TDWTF themselves. |
|
This isn't the dumb way to do it! Why, it looks positively Enterprisey(TM)(R)(WTF)! Far more impressive than some stupid call to a boring function like sleep(). |
Re: Raymond Chen on Sleep() Deprivation
2006-09-11 13:08
•
by
CDarklock
|
Generally 3-5 years of experience at each level, so if you have 9-10 years of experience, you're either at the high end of II or the low end of III. Lead software developers are usually directly responsible for the success of one project, and chief software developers for several simultaneously. I think the purpose of the survey is to see if they should do job postings here. |
|
Could be worse; I've seen more than one programmer who, when tasked to do something like "wait 5 seconds", writes this code or similar: DateTime end = DateTime.Now.AddSeconds(5); while(end < DateTime.Now) { for (int ii = 0; ii < 100000; ii++) { } } It has all the beauty of ignoring something like Sleep, *and* will spike the CPU to 100% for however long it's waiting for. |
|
Maybe he needed a more accuracy than the 10ms resolution Sleep() provides?
|
Re: Raymond Chen on Sleep() Deprivation
2006-09-11 13:30
•
by
themagni
|
Yes! I've seen this many, many times. I've tried to explain that this makes the code unstable. It's like talking to a really dumb rock. (In all fairness, sometimes you don't have "sleep".) It just inserts a race condition. How do you know if it's always going to be 6 seconds? Will you pause for long enough? Will you crash? Will your compiler optimise out the loop that has nothing in it? Who knows? It works now; ship that mofo! |
Re: Raymond Chen on Sleep() Deprivation
2006-09-11 13:35
•
by
kipthegreat
|
I have to confess that I did almost exactly this, when I first learned VB. I was in high school at the time, if that makes it more acceptable.. Although, shouldn't it be "while(DateTime.Now < end) {" instead? |
Re: Raymond Chen on Sleep() Deprivation
2006-09-11 13:42
•
by
JoeBloggs
|
I did a lot of that in my early programming. In my defense, I was programming on a Commodore 64, which had neither a sleep() function nor any concept of multitasking.
|
Re: Raymond Chen on Sleep() Deprivation
2006-09-11 13:47
•
by
Manni
|
Good pull kip. And my favorite implementation of this so far was where the program would execute some external program (I think it might have been a batch file) and wait for the external dude to finish before resuming the program. The external program would basically sleep for 5 seconds, and then exit. Well...not always. |
|
Uhh, I guess someone forgot about maybe doing this Thread.Sleep() |
|
I can't believe no one has yet pointed out that the code leaks the waitable timer if it succeeds!
|
Re: Raymond Chen on Sleep() Deprivation
2006-09-11 13:50
•
by
englebert
|
|
The real danger here is that if you are running on a Xell 2600 without a BIOS patch (must be a MS problem<-> must be a Xell problem), and the system clock stops advancing while you are in this loop, you will burn 100% of the CPU for a long time. Homework: Devise a "health check" that can determine if the system clock has stopped. Hint: Have an external system provide a hearbeat. Note: We switched back to HP servers. |
Re: Raymond Chen on Sleep() Deprivation
2006-09-11 14:07
•
by
Well, perhaos the SetWaitableTimer is more acurate than Sleep()
|
|
Maybe they want 60 seconds to the exact microsecond. hmm no. This is bad code though because it sounds as if the 60 seconds has been selected because it avoids some contention problem. The
|
|
The real WTF here isn't the lack of using Sleep, nor the bug
Sleep(60000) followed by ExitThread(0) is definitely better, but I suspect that this function shouldn't exist in the first place. No matter how you code this function, it is still a WTF. |
Re: Raymond Chen on Sleep() Deprivation
2006-09-11 14:29
•
by
merreborn
|
Wow. I'm pretty sure the system clock stopping would break a *lot* of code...
Captcha: craptastic. It's like the captcha can read my mind! |
Re: Raymond Chen on Sleep() Deprivation
2006-09-11 14:58
•
by
Bus Raker
|
The difference is about $50 -$100 K a year. If you're under $50K, you're a 'I'. If you're over $100K, you're a 'IV' Is it just me, or is Foosball girl looking extra perky today? |
Re: Raymond Chen on Sleep() Deprivation
2006-09-11 15:03
•
by
joe bruin
|
|
Finally, a real code WTF. On Unix systems, it's not uncommon to see the select(2) system call as a portable version of sleep() (it even works on Windows). Not so common nowadays as way back in the day. |
Re: Raymond Chen on Sleep() Deprivation
2006-09-11 15:15
•
by
Grimoire
|
Sorry, beat you to it my half an hour. But I'm glad that we are in agreement! |
Re: Raymond Chen on Sleep() Deprivation
2006-09-11 15:17
•
by
snoofle
|
What happens in 2038 when end < now ? |
Re: Raymond Chen on Sleep() Deprivation
2006-09-11 15:24
•
by
kbiel
|
|
Um, what is the Now() equivalent on a C64? Just curious because I always found it hard to work up such timers on a system that had no concept of time structures nor even possessed a real time clock.
CAPTCHA: truthiness - Perfect for this comment. |
Re: Raymond Chen on Sleep() Deprivation
2006-09-11 15:33
•
by
Erlando
|
Then we wait...... |
Re: Raymond Chen on Sleep() Deprivation
2006-09-11 15:34
•
by
TheMuuj
|
|
That sounds like a *nix problem to me. Well, some Windows programs will have that problem, too, but .NET programs shouldn't (but I don't put anything past people who went to WTFU).
|
Re: Raymond Chen on Sleep() Deprivation
2006-09-11 15:44
•
by
themagni
|
And I beat you by an hour. ;) We all agree that the code is bad - not by design, but by existence - then we're all thinking the right thing. If this was a perfect implementation, it would still be a WTF. Delays don't fix problems. They hide them. (Yes, there are valid reasons for waiting. This is not one of them.) |
Re: Raymond Chen on Sleep() Deprivation
2006-09-11 15:50
•
by
skington
|
You can have a timer without a real-time clock. The BBC B had a timer, but it wasn't battery-backed, so it told you the number of seconds since the last restart. |
Re: Raymond Chen on Sleep() Deprivation
2006-09-11 15:52
•
by
Grimoire
|
I feel the shame... :) This is why people who don't know proper threading techniques shouldn't code in a multithreaded environment. Its kind of funny how most people say things like "OMG! Just use sleep!!!!" or "Haha! He's not cleaning up the timer handle". Those aren't the WTFs here. Yeah, they are silly, or a bug, but not really WTFs. |
Re: Raymond Chen on Sleep() Deprivation
2006-09-11 15:54
•
by
verisimilidude
|
On a C64 it was OK to use a busy loop to do timing. There was no threading, other than what you implemented, so the processor had nothing else to do. Interrupts were minimally supported so possibly you could have used the sound device. That was handled by a special purpose chip so you could play music while the 6502 processor did something else. |
Re: Raymond Chen on Sleep() Deprivation
2006-09-11 15:56
•
by
SomeCoder
|
|
This is a great WTF. First of all, you get the little WTFs of him not cleaning up the handles and such. Then you get the slightly larger WTF of him reinventing the wheel when you could just call sleep(). Then you get the ultimate WTF of him trying to fix a race condition, by sleep()ing. This WTF is indeed, Brillant ;) |
Re: Raymond Chen on Sleep() Deprivation
2006-09-11 16:04
•
by
gfhjgfukygukgkhjfgh
|
|
Re: Raymond Chen on Sleep() Deprivation
2006-09-11 16:17
•
by
AbominousCoward
|
|
Besides which select() has better resolution than sleep() on many systems (which is a WTF in and of itself). Don't ask how I know - I spend to much time in !sleep() state Captcha quality (oxymoron wtf?) |
Re: Raymond Chen on Sleep() Deprivation
2006-09-11 16:23
•
by
WWWWolf
|
Commodore 64 *does* have a real time clock. It doesn't record date, though, and it's not battery-backed-up. You can pull its value from BASIC variable TI$. I have no idea how to read it via machine language, but I seem to remember there was a KERNAL call for that. (I wonder what RDTIM does, maybe it does something related. =) And in case you're curious: If your system doesn't have a RTC, you probably have other sources of constantly-updating things. If C64 didn't have a RTC, I'd probably hook something to the raster interrupt (Just update your second counter every 25th screen update, or something... I've done a raster interrupt thing only once so I can't remember when or how the stuff works) or via some other clock chip (C64 has CIA chips, which have programmable timer interrupts, I think).
|
Re: Raymond Chen on Sleep() Deprivation
2006-09-11 16:28
•
by
WWWWolf
|
Oh yeah? PRINT TI$ READY. READY. READY.
|
Re: Raymond Chen on Sleep() Deprivation
2006-09-11 16:33
•
by
joe bruin
|
Wow, this may be the first time that two or more programmer have agreed about a non-trivial issue on this site. And I totally missed both of your posts. It's nice to see a good WTF bringing people together against its creator. |
Re: Raymond Chen on Sleep() Deprivation
2006-09-11 16:57
•
by
ParkinT
|
Now THAT is funny! :-) |
Re: Raymond Chen on Sleep() Deprivation
2006-09-11 17:07
•
by
Alexis de Torquemada
|
for (int i = 0; i <= 10; ++i) {
|
Re: Raymond Chen on Sleep() Deprivation
2006-09-11 18:10
•
by
Anonymous Coward
|
The latter is fed intravenously. |
Re: Raymond Chen on Sleep() Deprivation
2006-09-11 18:37
•
by
triso
|
Does anyone know where Alex went for vacation? I hope they don't sell sparklers there.... |
Re: Raymond Chen on Sleep() Deprivation
2006-09-11 19:28
•
by
Jon
|
.NET's DateTime goes up to the end of year 9999. Even Microsoft can make a patch in that timeframe. :-) |
Re: Raymond Chen on Sleep() Deprivation
2006-09-11 19:50
•
by
Duh
|
And in the BASIC code which made the form so popular, the $TIME or $TI was a measure of clock ticks since start up, so anyone who turned their computer off each night or for any other reason restarted on a near-daily basis, that wouldn't be a problem. |
Re: Raymond Chen on Sleep() Deprivation
2006-09-11 20:06
•
by
Morty
|
|
TheMuuj wrote the following post at 09-11-2006 3:34 PM:
Yup. Easily fixable in theory, except for legacy issues. http://en.wikipedia.org/wiki/Year_2038_problem |
Re: Raymond Chen on Sleep() Deprivation
2006-09-11 20:36
•
by
Stephen Jones
|
Even worse, when waiting for
|
Re: Raymond Chen on Sleep() Deprivation
2006-09-11 21:00
•
by
RyuO
|
The roman numerals sound like what the government contractors use for slots. What it really means is pay grade, i.e., how much salary you can command. In the real world, hiring managers and recruiters invariably use shorthand terms called "Junior", "Midlevel" and "Senior" for how good you actually are. The precise definitions vary, but I use the definitions an old management mentor taught me:
So, if I hire a junior programmer, it does not mean I want a bad one, it means I want someone who can follow precise instructions. Naturally, someone that can handle a higher degree of autonomy will tend to make more money. Having greater technical skill generally means you are more autonomous, but there are plenty of exceptions. Lots of people with mediocre skills can manage themselves, and they are usually more valuable to an employer than an ace who needs to be watched. |
| « Prev | Page 1 | Page 2 | Next » |