←back to thread

345 points splitbrain | 1 comments | | HN request time: 0s | source
Show context
OsrsNeedsf2P ◴[] No.41837682[source]
I love how simple this is- Barely 100 lines or C++ (ignoring comments). That's one thing that makes me prefer X11 over Wayland.
replies(8): >>41837906 #>>41838181 #>>41838339 #>>41838393 #>>41838489 #>>41838500 #>>41838693 #>>41844644 #
asveikau ◴[] No.41838339[source]
The code is a little weird. There is no XLib event loop. It calls sleep(100) in a loop until it hits SIGINT. That will have high cpu usage for no reason.
replies(3): >>41838378 #>>41844664 #>>41848003 #
diath ◴[] No.41838378[source]
It will not, even adding just a 1ms sleep in a loop will drop CPU usage to barely noticeable levels, 10 wakes a second is barely anything for any CPU from the past 3 decades.
replies(5): >>41838399 #>>41839735 #>>41840345 #>>41845898 #>>41848081 #
Too ◴[] No.41840345{3}[source]
It’s a good way to drain your battery on mobile devices, even if usage looks low.

Not that this matters for this particular tool.

replies(1): >>41840661 #
erickj ◴[] No.41840661{4}[source]
> Not that this matters for this particular tool.

Then the code is perfectly appropriate.

replies(1): >>41840806 #
quotemstr ◴[] No.41840806{5}[source]
It's a bad example for others and a bad habit to get into. If every program did this, we'd have trouble getting CPUs into deep idle states.
replies(1): >>41841156 #
enriquto ◴[] No.41841156{6}[source]
It's an irrelevant implementation detail. This is for a live call. You are streaming video at the same time, so there's no point in worrying about idling.

I'd even say that it's a good example for others, because the equivalent code with the event loop would be slightly more complicated (maybe 5 more lines?). Striving for "doing things right" when the wrong thing is perfectly appropriate would be a bad example.

replies(3): >>41841764 #>>41843788 #>>41845979 #
drdaeman ◴[] No.41843788{7}[source]
> You are streaming video at the same time, so there's no point in worrying about idling.

I'd argue it's completely opposite of this. You're streaming video, already putting some significant stress on the system. No reason to waste time (even if it's a minuscule amount) to make things worse.

> Striving for "doing things right" when the wrong thing is perfectly appropriate would be a bad example.

And that's how we ended with e.g. modern IoT that kinda sorta works but accumulation of minor bad decisions (and some less minor bad decisions for sure) ends up making the whole thing a hot mess.

replies(1): >>41848024 #
1. account42 ◴[] No.41848024{8}[source]
Sleeping for 100ms between checking for events will not produce a noticeable CPU load. The only reason this would drain the battery is because it can prevent the CPU from entering deeper powersaving states - but even for that 100ms is an eternity and video streaming will prevent that anyway.