LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 02-13-2005, 01:19 PM   #1
keiwu
Member
 
Registered: Feb 2005
Posts: 77

Rep: Reputation: 15
pthread's programming problem


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.

The program will end when seats_available is 0.

and constructive idea is welcomed.
 
Old 02-13-2005, 09:07 PM   #2
ringerxyz
LQ Newbie
 
Registered: Nov 2004
Location: China
Distribution: red-flag
Posts: 16

Rep: Reputation: 0
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
 
Old 02-13-2005, 11:42 PM   #3
keiwu
Member
 
Registered: Feb 2005
Posts: 77

Original Poster
Rep: Reputation: 15
Quote:
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.
 
Old 02-14-2005, 01:17 AM   #4
ringerxyz
LQ Newbie
 
Registered: Nov 2004
Location: China
Distribution: red-flag
Posts: 16

Rep: Reputation: 0
Is your programe used for simulation ?
if so,the random seed is not enough,because it's average rate will be 1:1
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Qt Programming Problem chanwing Programming 7 04-20-2005 04:18 AM
programming problem..........help urgent djadhav Programming 5 10-20-2004 04:47 AM
another c programming problem Randall Programming 8 01-29-2003 04:45 PM
simple c programming problem abi_sh Programming 8 07-24-2002 08:40 PM
Socket programming problem krivi Programming 3 01-14-2002 02:04 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 10:07 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration