philosophers's People
philosophers's Issues
食べた回数に関する実装
全員がn
回食べたタイミングで終了させる必要がある
どうやって止めようか?
n回食べた後に死ぬ場合、行き続けさせる
食べている途中で死ぬのはOKか?
`n = 1` のケース
コールバック関数に渡すポインタの型の設計
方針
typedef struct s_args
{
int number_of_philosophers;
int die_ms;
int eat_ms;
int sleep_ms;
int eat_limit;
bool has_limit;
} t_args;
typedef struct s_philosopher
{
int id;
size_t last_ate_at;
int eat_count;
} t_philosopher;
typedef struct s_vars
{
t_args *args;
t_philosopher *philosopher;
pthread_mutex_t *forks;
} t_vars;
とりあえずこうした
初期化のときは、args
, forks
を生成し、そのポインタを使いまわすことにする(同じデータをすべての哲学者が共有する)
philosopherの数だけ t_vars
を作成する
但し、 t_vars
の要素の中で、philosopher
のみを新たに初期化をする
理由
- スレッドに渡せる変数は1つである
- スレッドには、競合するデータ以外は独立した変数を割り当てる必要が有る
fork
は共通で持っておく必要が有るargs
は スレッド内ではread only なのでどちらでもよい- philosopherは独立したデータを持っておく必要が有る
- ID(というかforkを指定する変数)が必要
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.