Обратите внимание, что новости можно получать по RSS.
X
-

Информационные технологии, IB NEWS - архив

10 декабря 1998, 00:00 (9262 дня назад, №6133)Is_computer_on? ;-)

Немного о веселом. Думаю, лучше без перевода:

^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
DEVELOPERS' WORKSHOP: The Refrigerator Question
By Eric Shepherd -- <sheppy@be.com>
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

Of all the functions the BeOS provides to programmers, one of the least understood and most widely debated is is_computer_on(). Documentation has been sketchy, and developers have debated the best use for this function. This week, we'll investigate is_computer_on() in depth.

Some developers claim that this function always returns 1, and say that it's a sham. They say their tests have produced significant empirical evidence to this effect. Others offer circumstantial evidence, such as "programs can't run when the computer's off," which doesn't really explain anything.

This is a lot like trying to figure out if the light stays on in the refrigerator when you close the door. How can you be sure that is_computer_on() isn't returning some other value when the computer's off? Let's look at a test program:

#include <OS.h>
#include <stdio.h>

int main(void) {
int i;

printf("# Result\n");
printf("----- ------\n");
for (i=1;i<=25;i++) {
printf("%-5d %ld\n", i, is_computer_on());
}
return 0;
}

If you run this program, you get the following output:

# Result
----- ------
1 1
2 1
3 1
4 1
5 1
6 1
7 1
8 1
9 1
10 1
(and so on)

Now try running the program and shutting off your computer while it's running. Unfortunately, printf() doesn't work reliably in this case; you don't see your output, because the computer's video hardware becomes unreliable when turned off. You might try customizing this code to write the output to disk, but unfortunately, hard drives also become unreliable when power isn't applied to them throughout their operation. Networking and serial ports likewise have a high failure rate when power is turned off.

In other words, the empirical evidence is a little flimsy. Due to failures beyond Be's control, test programs such as the one above can't present their full results. I'm not saying that is_computer_on() returns some other value when the computer isn't running, but this is a prime example of the difficulty encountered when testing a theory through code.

However, Be guarantees that is_computer_on() will always return 1 if the computer is running.


Опубликовано: DragonFa

Случайная заметка

8949 дней назад, 01:4319 октября 1999 Обнаружил online журнал "Computer Paper". В последнем номере есть несколько полезных статей:
- Сравнение различных PDA (около десяти) в одной большой статье. В частности оттуда я узнал что оказывается существует аналог именно Palm V от IBM - WorkPad C3
- Другая статья - review Psion Series 5mx.
- Review Psion NetBook.

Избранное

2541 день назад, 01:575 мая 2017 Часть 1: От четырёх до восьми Я люблю читать воспоминания людей, заставших первые шаги вычислительной техники в их стране. В них всегда есть какая-то романтика, причём какого она рода — сильно зависит от того, с каких компьютеров люди начали. Обычно это определяется обстоятельствами — местом работы, учёбы, а иногда и вовсе — ...далее

2053 дня назад, 20:305 сентября 2018 "Finally, we come to the instruction we've all been waiting for – SEX!" / из статьи про микропроцессор CDP1802 / В начале 1970-х в США были весьма популярны простые электронные игры типа Pong (в СССР их аналоги появились в продаже через 5-10 лет). Как правило, такие игры не имели микропроцессора и памяти в современном понимании этих слов, а строились на жёсткой ...далее