Option lock in procedures - Maple Help

Option lock in Procedures

 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:
 > $\mathrm{Threads}:-\mathrm{Task}:-\mathrm{Start}\left(\left(\right)↦\mathrm{NULL},\mathrm{Task}=\left[p,1\right],\mathrm{Task}=\left[p,2\right]\right)$
 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.