←back to thread

345 points splitbrain | 1 comments | | HN request time: 0.001s | 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 #
1. asveikau ◴[] No.41841764{7}[source]
My guess is that somebody coded that event-loop-less X client not really familiar with the language and how to write Xlib apps. I partially assume this because C, C++ and especially Xlib are becoming less popular over time, so finding skilled practitioners to write it idiomatically is relatively rare now. This basic event loop stuff is something that maybe belongs in a library. So they just wrote library grade functionality themselves, badly. The commentary here is getting defensive about doing things the wrong way, coming up with lots of post hoc justification.