Final answer:
Pseudo code to prevent total ticket sales from exceeding numtickets using a mutex lock.
Step-by-step explanation:
In order to ensure that the total number of tickets sold does not exceed the value of the global variable 'numtickets', we can use a mutex lock to synchronize access to the variable.
- Initialize a mutex lock.
- Lock the mutex before attempting to sell a ticket.
- Check if there are still tickets available.
- If there are tickets available, sell a ticket and increment the count of tickets sold.
- Unlock the mutex.
- Repeat the steps 2-5 until there are no more tickets available.
This pseudo code ensures that only one thread can access the 'numtickets' variable at a time, preventing the total number of tickets sold from exceeding the limit.