哲學家就餐問題

2021-05-27 12:34:43 字數 743 閱讀 4313

**:

本文是哲學家就餐問題在 linux 上的程式實現,與windows 平台的實現類似,

程式上稍有不同。

philosopherdining.cpp

#include #include #include #include #include #include "rasutil.h"

using namespace std;

const unsigned int philosopher_num=5;

const char thinking=1;

const char hungry=2;

const char dining=3;

// each fork has a semaphore

sem_t semph[philosopher_num];

// mutex for printing

pthread_mutex_t mutex;

void* philosopherproc(void* param);

int main(int argc, char* argv)

{ int i;

srand(getpid());

pthread_t philosopherthread[philosopher_num];

int phid[philosopher_num];

pthread_mutex_init(&mutex, null);

for (i=0; i

哲學家就餐問題

pragma once include include include include include include include include include include include include include stdafx.h handle chopstick 5 room l...

哲學家就餐問題

假設有五位哲學家圍坐在一張圓形餐桌旁,做以下兩件事情之一 吃飯,或者思考。吃東西的時候,他們就停止思考,思考的時候也停止吃東西。餐桌中間有一大碗義大利面,每兩個哲學家之間有乙隻餐叉。因為用乙隻餐叉很難吃到義大利面,所以假設哲學家必須用兩隻餐叉吃東西。他們只能使用自己左右手邊的那兩隻餐叉。哲學家就餐問...

哲學家就餐問題

問題描述 哲學家就餐 c c 語言 author erice s binbin erices 163.com date 2017 10 21 include include include include define max 5 五個哲學家 define left i max 1 max 佇列處理...