frontpage.
newsnewestaskshowjobs

Made with ♥ by @iamnishanth

Open Source @Github

fp.

Why a 'Boring' Life Might Be the Happiest One

https://karunpal.substack.com/p/why-a-boring-life-might-be-the-happiest
39•articsputnik•38m ago•5 comments

BERT Is Just a Single Text Diffusion Step

https://nathan.rs/posts/roberta-diffusion/
235•nathan-barry•3h ago•49 comments

Production RAG: what I learned from processing 5M+ documents

https://blog.abdellatif.io/production-rag-processing-5m-documents
130•tifa2up•2h ago•38 comments

AWS Multiple Services Down in us-east-1

https://health.aws.amazon.com/health/status?ts=20251020
1063•kondro•10h ago•1480 comments

TernFS – an exabyte scale, multi-region distributed filesystem

https://www.xtxmarkets.com/tech/2025-ternfs/#posix-shaped
21•kirlev•45m ago•1 comments

Alibaba Cloud says it cut Nvidia AI GPU use by 82% with new pooling system

https://www.tomshardware.com/tech-industry/semiconductors/alibaba-says-new-pooling-system-cut-nvi...
178•hd4•5h ago•130 comments

Space Elevator

https://neal.fun/space-elevator/
1213•kaonwarb•13h ago•264 comments

DeepSeek OCR

https://github.com/deepseek-ai/DeepSeek-OCR
747•pierre•11h ago•197 comments

How to stop Linux threads cleanly

https://mazzo.li/posts/stopping-linux-threads.html
89•signa11•5d ago•30 comments

AWS outage shows internet users 'at mercy' of too few providers, experts say

https://www.theguardian.com/technology/2025/oct/20/amazon-web-services-aws-outage-hits-dozens-web...
64•evolve2k•49m ago•26 comments

Optical diffraction patterns made with a MOPA laser engraving machine [video]

https://www.youtube.com/watch?v=RsGHr7dXLuI
49•emsign•6d ago•3 comments

Servo v0.0.1

https://github.com/servo/servo
332•undeveloper•5h ago•95 comments

Dutch spy services have restricted intelligence-sharing with the United States

https://intelnews.org/2025/10/20/01-3416/
60•Refreeze5224•56m ago•13 comments

Docker Systems Status: Full Service Disruption

https://www.dockerstatus.com/pages/incident/533c6539221ae15e3f000031/68f5e1c741c825463df7486c
289•l2dy•10h ago•115 comments

Entire Linux Network stack diagram (2024)

https://zenodo.org/records/14179366
501•hhutw•14h ago•41 comments

Chess grandmaster Daniel Naroditsky has passed away

https://old.reddit.com/r/chess/comments/1obnbmu/grandmaster_daniel_naroditsky_has_passed_away/
47•ntnbr•57m ago•13 comments

Show HN: Playwright Skill for Claude Code – Less context than playwright-MCP

https://github.com/lackeyjb/playwright-skill
92•syntax-sherlock•6h ago•33 comments

Automate all the things with Swift Subprocess

https://blog.jacobstechtavern.com/p/swift-subprocess
12•jakey_bakey•1w ago•1 comments

Modeling Others' Minds as Code

https://arxiv.org/abs/2510.01272
44•PaulHoule•4h ago•36 comments

Qt Group Buys IAR Systems Group

https://www.qt.io/stock/qt-completes-the-recommended-public-cash-offer-to-the-shareholders-of-iar...
43•shrimp-chimp•6h ago•25 comments

The Great Horse Manure Crisis of 1894: predictions of 9 feet of manure in cities

https://en.wikipedia.org/wiki/Great_horse_manure_crisis_of_1894
5•SweetSoftPillow•6d ago•2 comments

Pointer Pointer (2012)

https://pointerpointer.com
200•surprisetalk•1w ago•25 comments

The Peach meme: On CRTs, pixels and signal quality (again)

https://www.datagubbe.se/crt2/
56•zdw•1w ago•21 comments

Matrix Conference 2025 Highlights

https://element.io/blog/the-matrix-conference-a-seminal-moment-for-matrix/
114•Arathorn•6h ago•76 comments

Fractal Imaginary Cubes

https://www.i.h.kyoto-u.ac.jp/users/tsuiki/icube/fractal/index-e.html
46•strstr•1w ago•4 comments

Introduction to reverse-engineering vintage synth firmware

https://ajxs.me/blog/Introduction_to_Reverse-Engineering_Vintage_Synth_Firmware.html
168•jmillikin•15h ago•23 comments

Optimizing writes to OLAP using buffers (ClickHouse, Redpanda, MooseStack)

https://www.fiveonefour.com/blog/optimizing-writes-to-olap-using-buffers
26•oatsandsugar•6d ago•9 comments

Gleam OTP – Fault Tolerant Multicore Programs with Actors

https://github.com/gleam-lang/otp
176•TheWiggles•19h ago•79 comments

How to Enter a City Like a King

https://worldhistory.substack.com/p/how-to-enter-a-city-like-a-king
67•crescit_eundo•1w ago•62 comments

Commodore 64 Ultimate

https://www.commodore.net/product-page/commodore-64-ultimate-basic-beige-batch1
104•guerrilla•3h ago•49 comments
Open in hackernews

How to stop Linux threads cleanly

https://mazzo.li/posts/stopping-linux-threads.html
89•signa11•5d ago

Comments

ethin•2h ago
This was a fun read, I didn't know about rseq until today! And before this I reasonably assumed that the naive busy-wait thing would typically be what you'd do in a thread in most circumstances. Or that at least most threads do loop in that manner. I knew that signals and such were a problem but I didn't think just wanting to stop a thread would be so hard! :)

Hopefully this improves eventually? Who knows?

loeg•2h ago
Previously: https://news.ycombinator.com/item?id=38908556

And somehow just a day ago: https://news.ycombinator.com/item?id=45589156

leeter•2h ago
I'm reminded of Raymond Chen's many many blogs[1][2][3](there are a lot more) on why TerminateThread is a bad idea. Not surprised at all the same is true elsewhere. I will say in my own code this is why I tend to prefer cancellable system calls that are alertable. That way the thread can wake up, check if it needs to die and then GTFO.

[1] https://devblogs.microsoft.com/oldnewthing/20150814-00/?p=91...

[2] https://devblogs.microsoft.com/oldnewthing/20191101-00/?p=10...

[3] https://devblogs.microsoft.com/oldnewthing/20140808-00/?p=29...

there are a lot more, I'm not linking them all here.

loeg•2h ago
If you can swing it (don't need to block on IO indefinitely), I'd suggest just the simple coordination model.

  * Some atomic bool controls if the thread should stop or not;
  * The thread doesn't make any unbounded wait syscalls;
  * And the thread uses pthread_cond_wait (or equivalent C++ std wrappers) in place of sleeping while idle.
To kill the thread, set the stop flag and cond_signal the condvar. (Under the hood on Linux, this uses futex.)
OskarS•2h ago
The tricky part is really point 2 there, that can be harder than it looks (e.g. even simple file I/O can be network drives). Async IO can really shine here, though it’s not exactly trivial designing async cancelletion either.
asveikau•1h ago
Relying heavily on a check for an atomic bool is prone to race conditions. I think it's cleaner to structure the event loop as a message queue and have a queued message that indicates it's time to stop.
PaulDavisThe1st•1h ago
Every event loop is subject to the blocked-due-to-long-running-computation issue. It bites ...
a-dub•2h ago
this stuff always seemed a mess. in practice i've always just used async io (non-blocking) and condition variables with shutdown flags.

trying to preemptively terminate a thread in a reliable fashion under linux always seemed like a fool's errand.

fwiw. it's not all that important, they get cleaned up at exit anyway. (and one should not be relying on operating system thread termination facilities for this sort of thing.)

harvie•2h ago
while (true) { if (stop) { break; } }

If there only was a way to stop while loop without having to use extra conditional with break...

OskarS•2h ago
Feel free to read the article before commenting.
f1shy•1h ago
I’ve read it, and I found nothing to justify that piece of code. Can you please explain?
bartvk•1h ago
The while loop surrounds the whole thread, which does multiple tasks. The conditional is there to surround some work completing in a reasonable time. That's how I understood, at least.
f1shy•52m ago
Does not seem so clear to me. If so it could be stated with more pseudo code. Also the eventual need for multiple exit points…
hulitu•2h ago
> How to stop Linux threads cleanly

kill -HUP ?

quietbritishjim•1h ago
This is just doubling down on the wrong approach.

The right approach is to avoid simple syscalls like sleep() or recv(), and instead call use multiplexing calls like epoll() or io_uring(). These natively support being interrupted by some other thread because you can pass, at minimum, two things for them to wait for: the thing you're actually interested in, and some token that can be signalled from another thread. For example, you could start a unix socket pair which you do a read wait on alongside the real work, then write to it from another thread to signal cancellation. Of course, by the time you're doing that you really could multiplex useful IO too.

You also need to manually check this mechanism from time to time even if you're doing CPU bound work.

If you're using an async framework like asyncio/Trio in Python or ASIO in C++, you can request a callback to be run from another other thread (this is the real foothold because it's effectively interrupting a long sleep/recv/whatever to do other work in the thread) at which point you can call cancellation on whatever IO is still outstanding (e.g. call task.cancel() in asyncio). Then you're effectively allowing this cancellation to happen at every await point.

(In C# you can pass around a CancellationToken, which you can cancel directly from another thread to save that extra bit of indirection.)

rostayob•1h ago
This is noted in the blog post, but the problem is that sometimes you don't have the freedom to do so. See this sidenote and the section next to it: https://mazzo.li/posts/stopping-linux-threads.html#fn3 .
f1shy•1h ago
Should this code:

  while (true) {
    if (stop) { break; }
    // Perform some work completing in a reasonable time
  }

Be just:

  While(!stop){
    Do-the-thing;
  }
Anyway, the last part:

>> It’s quite frustrating that there’s no agreed upon way to interrupt and stack unwind a Linux thread and to protect critical sections from such unwinding. There are no technical obstacles to such facilities existing, but clean teardown is often a neglected part of software.

I think it is a “design feature”. In C everything is low level, so I have no expectation of a high level feature like “stop this thread and cleanup the mess” IMHO asking that is similar to asking for GC in C.

dathinab•1h ago
yes, maybe except if you don't have a single tight loop and stop checks are not just done once in the loop body but manually sprinkled through various places of your code (e.g. thing a long running compute task split into part 1,2(tight loop),3(loop),4 then you probably want a stop check between each of them and in each inner iteration of 3 but probably not in each inner iteration of 2 (as each check is an atomic load).
f1shy•1h ago
Maybe. But seems to me there should be better ways to organize the code. In the case you mention there will be many places where you have to cleanup (that is what the article is about) so the code will be hell to debug: multithreaded, with multiple exit points in each thread… I have done relly tons and tons of multithreading and never once needed such a conplicated thing. Typically the code which gets run in parallel is either for managing one resource type OR number crunching w/o resource allocation… if you are spawning threads that do lots of resource allocation, maybe you have architecture problems, or you are solving a very niche problem.
dathinab•1h ago
If your threads run "cooperative multi threading" task (e.g. rust tokio runtime, JS in general etc.) then this kinda is a non problem.

Due to task frequently returning to the scheduler the scheduler can do "should stop" check there (also as it might be possible to squeeze it into other atomic state bit maps it might have 0 relevant performance overhead (a single is-bit-set check)). And then properly shut down tasks. Now "properly shut down tasks" isn't as trivial, like the "cleaning up local resources" part normally is, but for graceful shutdown you normally also want to allow cleaning up remote resources, e.g. transaction state. But this comes from the difference of "somewhat forced shutdown" and "grace full shutdown". And in very many cases you want "grace full shutdown" and only if it doesn't work force it. Another reason not to use "naive" forced only shutdown...

Interpreter languages can do something similar in a very transparent manner (if they want to). But run into similar issues wrt. locking and forced unwinding/panics from arbitrary places as C.

Sure a very broken task might block long term. But in that case you often are better of to kill it as part of process termination instead and if that doesn't seem an option for "resilience" reasons than you are already in better use "multiple processes for resilience" (potentially across different servers) territory IMHO.

So as much as forced thread termination looks tempting I found that any time I thought I needed it it was because I did something very wrong else where.

PaulDavisThe1st•1h ago
user-space threads have entirely different semantics from kernel threads. both have their uses, but should generally not be conflated.
dathinab•42m ago
Concepts of cooperate multi threading, co-rutines etc. aren't limited to user space.

Actually they out date the whole "async" movement or whatever you want to call it.

Also the article is about user-space threads, i.e. OS threads, not kernel-space threads (which use kthread_* not pthread_* and kthreads stopping does work by setting a flag to indicate it's supposed to stop, wakes the thread and then waits for exit. I.e. it works much more close to the `if(stop) exit` example then any signal usage.

ibejoeb•1h ago
libcurl dealt with this a few months ago, and the sentiment is about the same: thread cancellation in glibc is hairy. The short summary (which I think is accurate) is that an hostname query via libnss ultimately had to read a config file, and glibc's `open` is a thead cancellation point, so if it's canceled, it'll won't free memory that was allocated before the `open`.

The write-up is on how they're dealing with it starts at https://eissing.org/icing/posts/pthread_cancel/.

the_duke•1h ago
For interrupting long-running syscalls there is another solution:

Install an empty SIGINT signal handler (without SA_RESTART), then run the loop.

When the thread should stop:

* Set stop flag

* Send a SIGINT to the thread, using pthread_kill or tgkill

* Syscalls will fail with EINTR

* check for EINTR & stop flag , then we know we have to clean up and stop

Of course a lot of code will just retry on EINTR, so that requires having control over all the code that does syscalls, which isn't really feasible when using any libraries.

EDIT: The post describes exactly this method, and what the problem with it is, I just missed it.

rostayob•38m ago
This option is described in detail in the blog posts, with its associated problems, see this section: https://mazzo.li/posts/stopping-linux-threads.html#homegrown... .
the_duke•25m ago
Ah, fair, I missed it when reading the post because the approach seemed more complicated.
quotemstr•40m ago
pthread cancelation ends up not being the greatest, but it's important to represent it accurately. It has two modes: asynchronous and deferred. In asynchronous mode, a thread can be canceled any time, even in the middle of a critical section with a lock held. However, in deferred mode, a thread's cancelation can be delayed to the next cancelation point (a subset of POSIX function calls basically) and so it's possible to make that do-stuff-under-lock flow safe with cancelation after all.

That's not to say people do or that it's a good idea to try.

rostayob•32m ago
Cancellation points and cancellability state are discussed in the post. In a C codebase that you fully control pthread cancellation _can_ be made to work, but if you control the whole codebase I'd argue you're better off just structuring your program so that you yield cooperatively frequently enough to ensure prompt termination.
teddyh•30m ago
Off-Topic: I surprised myself by liking the web site design. Especially the font.
vlovich123•10m ago
This seems like a lot of work to do when you have signalfd, no? That + async and non blocking I/O should create the basis of a simple thread cancellation mechanism that exits pretty immediately, no?