Hi there,
I real need ideas on how to solve these problems
A certain number of philosophers sit around a circular table. They spend their lives alternating between thinking and eating. In the original version of the problem, there are as many chopsticks on the table as the number of philosophers. The philosophers thus had to synchronize access to the chopsticks, with their neighbors.
For the current exercise, you will assume instead that each philosopher is provided with a pair of chopsticks and can start eating at any point of time. Each philosopher will think for a random amount time between 0 and 6 seconds and eat for time between 0 and 3 seconds. All philosophers start out thinking. Your program, philos, will take as input the number of philosophers (N) and the number of times each philosopher will alternate between thinking and eating (M). The philosophers write to output their unique id (between 0 and (N-1)) and their current state at every transition. The program terminates after all philosophers have completed M transitions, printing the "Done." on a separate line.
You are to build a threaded program: Each "philosopher" must execute in a separate thread.
Sample invocation : ./philos 5 3
Sample output :
Philos 0 : Thinking.
Philos 1 : Thinking.
Philos 2 : Thinking.
Philos 3 : Thinking.
Philos 4 : Thinking.
Philos 0 : Eating.
Philos 1 : Eating.
Philos 1 : Thinking.
Philos 3 : Eating.
Philos 2 : Eating.
Philos 2 : Thinking.
Philos 4 : Eating.
Philos 1 : Eating.
Philos 2 : Eating.
Philos 0 : Thinking.
Philos 3 : Thinking.
Philos 0 : Eating.
Philos 4 : Thinking.
Philos 3 : Eating.
Philos 4 : Eating.
Done.
Hints: use the following man pages
pthread_create, pthread_join
random
sleep
make
gcc
gdb (issue an "add gnu" command to get access to the Gnu Debugger)
Implement a user-level non-preemptive threads library mythreads.a with the following methods:
mythread_create
mythread_yield
mythread_join
mythread_exit
These methods have the same signature as their corresponding counterparts in the previous exercise with pthread_ replaced by mythread_. You should implement simple FCFS (first come first serve) as a scheduling policy using a doubly linked queue of threads, including an idle thread. Also, think carefully about the semantics of the join operation and consider using a wrapper function to invoke the actual thread function for a newly create thread. (What is the relation between the wrapper and the join operation?)
You cannot use any of the pthread_XXX or thr_XXX routines, you have to exclusively use the _lwp_XXX routines below. The idea is to design and implement your own threading library.
Hints: use the following man pages
getcontext
_lwp_makecontext
_lwp_create, _lwp_exit
_lwp_suspend, _lwp_continue
Mathiew
Operating systems
RE:Operating systems
You mean, in effect, you want us to do your homework for you?
(hint: If you can -write- that description, you can figure out how to implement it. Therefore, you were given that description by someone else. Therefore it is probably homework, since work-related stuff would have you run on pthreads and wouldn't involve an implementation of the dining philosophers problem.)
(hint: If you can -write- that description, you can figure out how to implement it. Therefore, you were given that description by someone else. Therefore it is probably homework, since work-related stuff would have you run on pthreads and wouldn't involve an implementation of the dining philosophers problem.)
www.indiantranslator.com
Please visit www.indiantranslator.com for translations to Indian and International Languages at nominal charges.
RE:Operating systems
If you don't do your own home work you will never learn the most important part of programming, problem solving. Know syntax is great, knowing what to do with it is even better. Good Luck
-VoidLogic
P.S. 1. State the Problem [X]
2. Get a mental picture of how the final solution should work [ ]
3. Develope and algorithm [ ] (take your time here)
4. Code, Debug [ ]
5. Revise, goto 4 until your satified with your qaulity [ ]
-VoidLogic
P.S. 1. State the Problem [X]
2. Get a mental picture of how the final solution should work [ ]
3. Develope and algorithm [ ] (take your time here)
4. Code, Debug [ ]
5. Revise, goto 4 until your satified with your qaulity [ ]