GithubHelp home page GithubHelp logo

philosophers's People

Contributors

akkyorz avatar

Watchers

 avatar

philosophers's Issues

コールバック関数に渡すポインタの型の設計

方針

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. スレッドに渡せる変数は1つである
  2. スレッドには、競合するデータ以外は独立した変数を割り当てる必要が有る
    1. fork は共通で持っておく必要が有る
    2. args は スレッド内ではread only なのでどちらでもよい
    3. philosopherは独立したデータを持っておく必要が有る
  3. ID(というかforkを指定する変数)が必要

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.