Option lock in Procedures - Maple Programming Help

Online Help

All Products    Maple    MapleSim

Home : Support : Online Help : Programming : Input and Output : File Manipulation : lock

Option lock in Procedures


Calling Sequence



Calling Sequence

option lock



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.


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


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


Procedure options