On Wed, Jan 26, 2011 at 02:33:56PM +0000, Alexander Konovalov wrote:
> Dear Georges,
> 
> On 25 Jan 2011, at 08:59, bolbita wrote:
> 
> > Dear GAP Forum,
> > 
> > I have little experience with GAP, and I wonder how can we control the 
> > execution time of a function.
> > I dream about a function like
> > UnderTimeControl := function (f, arg, maxtime)
> > which would run the function f with arguments arg and a timer in parallel,
> > and would return the result of f(arg) whenever its execution time is less 
> > than maxtime and would return fail 
> > otherwise.
> 
> The current version of GAP is single-threaded so it's not directly possible
> to have exactly the scenario you've described.However, there are several
> possible workarounds of various difficulty and flexibility:

If that may help, this is how I implemented something similar in PARI/GP
(which is also single-threaded):

1) add a signal handler for SIGALRM
2) call the C function alarm(maxtime);
3) evaluate f(arg).
4) if the signal handler is called, stop the evaluation and return fail.
5) if 3) complete, call alarm(0) to disable the alarm.

Cheers,
Bill.

_______________________________________________
Forum mailing list
Forum@mail.gap-system.org
http://mail.gap-system.org/mailman/listinfo/forum

Reply via email to