Option lock in procedures - Maple Help
For the best experience, we recommend viewing online help using Google Chrome or Microsoft Edge.

Online Help

All Products    Maple    MapleSim


Option lock in Procedures

 

Calling Sequence

Description

Examples

Calling Sequence

option lock

Description

• 

Adding option lock to a procedure protects that procedure from being run simultaneously with any other option-lock procedure in multiple threads. There can be only one thread running a procedure with option lock at a time.  If a second thread tries to run a procedure with option lock, then the second thread will block, waiting until the first thread's procedure is done. Other threads are free to run any other procedure.  The thread that "has the lock" is free to run any procedure, including those with option-lock.

Examples

p := proc(n)
   option lock;
   printf("Running p %d\n",n);
   Threads:-Sleep(1);
   printf("Done p %d\n",n);
end proc:

Threads:-Task:-StartNULL,Task=p,1,Task=p,2

Running p 2
Done p 2
Running p 1
Done p 1

Notice that the first procedure that begins to run starts and finishes before the second procedure can begin. Without option lock, you would see two "Running" statements printed before two "Done" statements.

See Also

CodeTools:-ThreadSafetyCheck

Procedure options

Procedures