Destroy - Maple Help
For the best experience, we recommend viewing online help using Google Chrome or Mozilla Firefox.

Online Help

All Products    Maple    MapleSim


Threads[Mutex]

  

Destroy

  

free resources used by mutexes

 

Calling Sequence

Parameters

Description

Examples

Calling Sequence

Destroy( mutexid1, mutexid2, ... )

Parameters

mutexidi

-

(integer) mutex identifier

Description

• 

The Destroy command releases the resources associated with the mutexes specified as arguments.

• 

To create a mutex, use the Create 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;

p≔procmglobalcount;print⁡count;count ≔ count+1end proc

(1)
> 

count≔1

count≔1

(2)

Create ten threads running the p function.

> 

ThreadsWait⁡seq⁡ThreadsCreate⁡p⁡m,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;

p≔procmglobalcount;Threads[Mutex][Lock]⁡m;print⁡count;count ≔ count+1;Threads[Mutex][Unlock]⁡mend proc

(4)
> 

count≔1

count≔1

(5)
> 

m≔ThreadsMutexCreate⁡

m≔1

(6)

Create ten threads running the new p function.

> 

ThreadsWait⁡seq⁡ThreadsCreate⁡p⁡m,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.

> 

ThreadsMutexDestroy⁡m

See Also

Threads

Threads[Create]

Threads[Mutex]

Threads[Mutex][Create]

Threads[Mutex][Lock]

Threads[Mutex][Unlock]