jonathanstowe / TermReadKey

Character mode terminal access for Perl
12 stars 27 forks source link

thread-safe or not? #17

Closed petamem closed 5 years ago

petamem commented 8 years ago

Could you please confirm that Term::ReadKey is or is not thread-safe? I experience quite a lot of crashes of Term::ReadKey 2.33 in a forking environment under Windows.

jonathanstowe commented 8 years ago

The module is not designed with thread safety in mind, (it pre-dates threading in Perl and fork emulation on Windows,) so it would be fairly safe to assume it won't play nicely in a threaded environment.

Specifically the XS parts of the module make calls to functions in the system C library which are probably not re-entrant in most implementations, and there are several static "global" variables in the XS code itself that are used to retain state which would also militate against its being "thread-safe"..

While it would be theoretically possible to make a module that does what Term::ReadKey does in a more thread-safe manner, it would almost certainly have to be a new and separate module as it would need a completely different interface style

jonathanstowe commented 5 years ago

I'm going to close this as I guess the above answers the question.