Hello Alexander,
On 2025-09-19 22:18, Alexander Tormasov via users wrote:
What if I should kill the thread which hangs in some unknown state? Eg it try to read smart card which was forcibly removed? Any mechanism to isolate consequences? This is a real life example for kind of embedded devices…
Threads are rarely an adequate mechanism for isolating trouble. They are more commonly a mechanism for introducing trouble. Unless in need to distribute computational work across multiple CPU cores, I would shy away from using threads.
Your smart-card interaction problem may best be solved by implementing the component as a state machine by explicitly modelling the flakiness of the smartcard and *never* block for I/O in the first place. A good example is the modem driver, which stays responsive regardless of all the silly things the modem is doing.
[1] https://github.com/genodelabs/genode-allwinner/tree/master/src/driver/modem/...
Alternatively, you can wrap the fragile smart-card interaction in a separate component, monitor its health from the outside, and re-spawn it when needed. So you plan ahead for its anticipated failure. This is the approach taken by the depot-download [2] tool to protect itself from all kinds of trouble (network connectivity, archive extraction, etc.).
[2] https://github.com/genodelabs/genode/tree/master/repos/gems/src/app/depot_do...
Cheers Norman