ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
the problem is this:
AirCanada has 100 seats available for flight888, and there are 10 travel agents that's selling these 100 seats. So I am going to use 10 threads to indicate the 10 travel agents. Whichever a thread book a seat, the seats_available is decrement by 1. Basically the seats_available is a global variable. The ratio of booking/cancelling is 3:1, so every 3 seats booking will result a seat of cancelling.
I have to avoid the any two or more threads updating the seats_available at the same time. So what should I do? how do I code it in c or c++ that will act in a way so every 3 seats booked and 1 seat will be canceled? do I need to use random seed for the 10 threads to decide which one is going to perform some kind of action.
you should reference some thread synchronization issues ,actually it's very easy,you can use Mutex or semaphore,
btw,I am not very clear about what you said "so every 3 seats booking will result a seat of cancelling."
good luck
Originally posted by ringerxyz you should reference some thread synchronization issues ,actually it's very easy,you can use Mutex or semaphore,
btw,I am not very clear about what you said "so every 3 seats booking will result a seat of cancelling."
good luck
Indeed it's quite easy!! But do I need a random seed to handle when each thread to make a booking/cancelling.
what I meant by ""so every 3 seats booking will result a seat of cancelling." is that 75% of the peple will make a booking and 25% will make a cancelling.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.