lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]

Florian Weimer <fw <at>> writes:
> [...] (This assumes that the CLR
> does not support thread cancellation, which it probably doesn't
> because it's difficult to get the semantics right.) [...]

Actually the CLR allows abortion of a managed thread by injecting an exception
which unwinds the thread, properly executing exception handling clauses for
cleanup. If you catch the exception and don't rethrow yourself, the runtime will
rethrow the abort exception automatically once you leave the exception handling
clause. To avoid that you can use an API call to stop the abortion process. The
initial abort exception is not raised arbitrarily, the runtime does some work to
only raise it in "safe" locations (whatever that may be, but it probably is
defined in the ISO/ECMA standard).

It pretty much looks like a big hack to me, especially the "stop abort" API
which basically is a dirty way to say 'yes I really meant to catch that
exception, it wasn't a mistake'. But when it comes to practical usage I have to
say it actually works very well, embedding applications (ASP, SQL) are using it
quite often and effectively to abort runaway threads or 'cancel' operations
which are no longer necessary. It's a good compromise to a hard abort (which
still may be necessary if the exception based abort doesn't terminate in a
reasonable time).