Re: [hatari-devel] Deadlock while closing serial port |
[ Thread Index |
Date Index
| More lists.tuxfamily.org/hatari-devel Archives
]
- To: hatari-devel@xxxxxxxxxxxxxxxxxxx
- Subject: Re: [hatari-devel] Deadlock while closing serial port
- From: Thomas Huth <th.huth@xxxxxxxxx>
- Date: Sat, 30 Apr 2022 09:04:04 +0000
- Dkim-signature: v=1; a=rsa-sha256; c=relaxed/simple; d=posteo.de; s=2017; t=1651309448; bh=z1ThmIE52JkzK9uqNyLDue12rPCR/eAgAkGvy4kS3hM=; h=Date:From:To:Subject:From; b=CfUzxWBWHZDHsGizdxUPTBXscVHn1lQPagNoL+o0q/0I3Ae2meCQ4ED1tSlkrzkQL k6lOUFwDIBVkP/MM0177HrJ0QxAtIyi+/uumFDJQzabWV07BzHasW2P4MZDWs6Wz/n 3ZL+JE6wcm1buwpoFgQvE7dSHAMgwlgufJYZJSYOT4P4E+M8j18zh7QdGgs3jTzGqT 1HA6rmkR97sLgC0I05Dro1PbK9nLiAeneR2LvvYooNKFzG4YxNocje1lqpVew22VuU TH7SAdIwhqCNnTtfSSYY9DLrYMJJp8BS0TJOY89ycyVqp7kDnLLNHO476xu1BFmuIS yPQkT7ChsNk5A==
Am Mon, 25 Apr 2022 02:11:38 +0300
schrieb Eero Tamminen <oak@xxxxxxxxxxxxxx>:
> Hi,
>
> On 24.4.2022 20.04, Thomas Huth wrote:
> > Am Sun, 24 Apr 2022 17:58:19 +0200
> > schrieb Christian Zietz <czietz@xxxxxxx>:
> >> today, I encountered a deadlock while running Hatari attached to a
> >> (real) serial port. This is on Linux, Debian 10, on a Raspberry Pi 400.
> > [...]
> >> At least with the C library used on my system fclose() blocks until any
> >> pending reads return. As a proof: If I force the device on the serial
> >> port to transmit some characters, the deadlock is broken and Hatari
> >> terminates.
> >>
> >> I therefore suggest either kill the RS232 thread or use non-blocking
> >> reads to that it can be terminated cleanly before calling fclose().
> >
> > now that's quite unfortunate ... There used to be a SDL_KillThread()
> > function in SDL 1.2, which we also used in older versions of Hatari (see
> > commit 90382329895415c952), but it has been dropped in SDL 2, so there is
> > no way of killing the rs232 thread anymore... No clue how to get that
> > thread out of the blocked read now.
> >
> > Non-blocking reads would be way easier, of course - but that does not work
> > on Windows AFAIK. We could maybe scratch that since hardly anybody likely
> > uses RS232 on Windows anyway?
> >
> > Otherwise, I've got no idea how to fix that situation :-(
>
> Situation is even worse with BSD libc, as that does not implement
> fine-grained locking like Glibc does. Therefore RS232 has been
> completely broken e.g. on Mac since we switched to SDL2.
Outch. I completely forgot about this.
> Somebody would need to rewrite RS232 handling to use OS native
> primitives either for threading, or for select(). While Mac/BSD and
> Linux could probably use same implementation, Windows would need
> something else, i.e. some Windows user would need to contribute that
> support.
Another option is maybe to use glib in Hatari. glib has an portable
implementation of poll():
https://docs.gtk.org/glib/func.poll.html
Or we simply use O_NONBLOCK and get rid of the threading stuff here
completely - and declare that RS232 is not supported on Windows anymore
(I'm not sure whether the RS232 stuff works on Windows at all anymore,
so that maybe wouldn't be a big loss anyway).
Opinions?
Thomas