For example your regex, could be given 20ms to run and use a maximum of 8Mb of heap before it is interrupted. This can happen on a single thread and drop back to the caller if an exception is thrown. I'd love to see a language feature which defines the maximum stack and heap for a particular scope i.e. in C#:
Breaker.Heap(8.MiB(), () => {
Breaker.Time(200.Milliseconds(), () => {
// risky operation
});
});
(we already do the time breaker, but not the heap)Edit: correct calling convention.
Edit 2: add missing extension method brackets