Unlock - Maple Help
For the best experience, we recommend viewing online help using Google Chrome or Microsoft Edge.
Our website is currently undergoing maintenance, which may result in occasional errors while browsing. We apologize for any inconvenience this may cause and are working swiftly to restore full functionality. Thank you for your patience.

Online Help

All Products    Maple    MapleSim


Threads[Mutex]

  

Unlock

  

unload a mutex

 

Calling Sequence

Description

Examples

Calling Sequence

Unlock( mutexId )

Description

• 

The Unlock command releases the lock on the mutex with identifier mutexId.  The thread evaluating the call to Unlock should have previously acquired the lock by calling the Lock command.

• 

For more information on using mutexes, see the Mutex help page.

Examples

p := proc( m )
   global count;
   print( count );
   count := count+1;
end proc;

pprocmglobalcount;printcount;countcount+1end proc

(1)

count1

count1

(2)

Create ten threads running the p function.

ThreadsWaitseqThreadsCreatepm,i=1..10

1

2

3

4

5

6

6

8

8

10

(3)

Without mutexes the same value may be printed multiple times.  (You may have to execute this command multiple times to see this occur.)

p := proc( m )
   global count;
   Threads[Mutex][Lock]( m );

   print( count );
   count := count+1;

   Threads[Mutex][Unlock]( m );
end proc;

pprocmglobalcount;Threads[Mutex][Lock]m;printcount;countcount+1;Threads[Mutex][Unlock]mend proc

(4)

count1

count1

(5)

mThreadsMutexCreate

m1

(6)

Create ten threads running the new p function.

ThreadsWaitseqThreadsCreatepm,i=1..10:

1

2

3

4

5

6

7

8

9

10

(7)

Using a mutex allows you to control access to the shared variable.  Thus each number will be printed only once.

ThreadsMutexDestroym

See Also

Threads

Threads[Create]

Threads[Mutex]

Threads[Mutex][Create]

Threads[Mutex][Destroy]

Threads[Mutex][Lock]