Live data from Hacker News

How to programmatically find out if computer is on

haiku-os.org

51–60 of 197 posts

Re: How to programmatically find out if computer is on

#52
post #22

> If the computer isn't on, the value returned by this function is undefined. Shouldn't it just block until the computer turns back on? Probably interferes with pthreads.

Seems like a reasonable compiler would inline the most likely implementation as 1. So, while technically undefined, it's safe to assume that it will 'return' 1 regardless of the actual on/off state of the computer.

{return 1;} is clearly a faulty implementation, it's entirely possible that the computer is already turned off by the time the function is executed using power stored in the decoupling capacitors of the CPU.

Re: How to programmatically find out if computer is on

#54
While it is clearly a joke, it has a legitimate use as a syscall that does nothing so can be used to test the syscall process itself [1]. (Its cousin `is_computer_on_fire` is not a syscall.)

[1] https://github.com/haiku/haiku/commit/ccaac177f64038c160de6f...

Re: How to programmatically find out if computer is on

#55
post #52
post #22

Earlier quoted context omitted.

Seems like a reasonable compiler would inline the most likely implementation as 1. So, while technically undefined, it's safe to assume that it will 'return' 1 regardless of the actual on/off state of the computer.

{return 1;} is clearly a faulty implementation, it's entirely possible that the computer is already turned off by the time the function is executed using power stored in the decoupling capacitors of the CPU.

Since the behavior is undefined when the computer is off this implementation seems correct in your hypothetical as well.

Re: How to programmatically find out if computer is on

#56

> If the computer isn't on, the value returned by this function is undefined. Shouldn't it just block until the computer turns back on? Probably interferes with pthreads.

Hmm, it seems like you need to make sure the computer is on before calling this function, or else you run the risk of getting back undefined data. Seems like we also need a function that can be used to tell if the computer is on...

There's a syscall to check whether the computer is on so just call that before this and you'll be fine

Re: How to programmatically find out if computer is on

#57

I like how it also has support for the ENIAC platform. I kicked my family out of the house so I had room to install the ENIAC. Happy to hear there's an OS I can run on it to get real work done, like posting unfunny jokes for strangers on Hacker News.

It upsets me that this function's interface allows it to describe silly things like "an ENIAC running on a 68000" or "an Apple II running on SPARC". Wouldn't be an issue if C++ supported GADTs.

Re: How to programmatically find out if computer is on

#58

Earlier quoted context omitted.

There's an elegant FP solution that involves searching an infinite data structure using only a finite amount of computation -- actually, with precisely zero computation, because the machine isn't on. It's like lazy evaluation, only more lazy.

Wait. When the machine isn't on, P=NP! So our security systems are (useless | perfect)! I think there might even be other implications...

Nice job - having shown that P is the same as NP factorial will allow us to solve a lot of really hard problems!

Re: How to programmatically find out if computer is on

#60
Since the not-on result is 'undefined', a devilish implementer could return 1 for the off case, just to screw with people.

(How could this work in theory? Maybe the computer has a separate watchdog controller board which allows the computer to be turned on and off remotely, and that controller acts as a proxy for the API request.)

Post reply on HN