dining.C
上传用户:shtangtang
上传日期:2007-01-04
资源大小:167k
文件大小:1k
- #define __THREADS_MAIN
- #include <thread.h>
- #include "philosopher.h"
- #include "dining.h"
- dining::dining(int p_no)
- {
- p_fork = new mutex[p_no];
- for( philosophers=0;philosophers<p_no;philosophers++ )
- (void)new philosopher(philosophers,p_no,this);
- }
- dining::~dining()
- {
- do {
- cout << philosophers << " are left." << endl;
- p_finish.wait(p_single);
- } while( philosophers-- > 1 );
- cout << "Diner closing." << endl;
- }
- void dining::finished()
- {
- p_single.lock();
- p_finish.signal();
- p_single.unlock();
- }
- mutex& dining::fork(int p_no)
- {
- return p_fork[p_no];
- }