42-philosophers's People
42-philosophers's Issues
Use Enum
Lines 33 to 36 in a9987e9
this is a good place to use enum.
Forks
It may be a good idea to define a fork data structure that contains just that.
Line 47 in a9987e9
Then define functions like fork_take
and fork_release
that deals with all these mutex. This is an abstraction that allows you to write your code in a much more readable fashion. So your eat
function would call those instead.
Separate Actions
Lines 69 to 87 in a9987e9
When I was writing this project, it makes more sense to me to have separate functions to be called when a philosopher take an action, i.e. eat, sleep, think, die. I find this approach to be quite nice, since overally, my code would be quite easily adapted to the bonus part of the project.
I suppose, the way I have written the project is more like an object oriented approach, where a philosopher is an object, and it can take actions.
Forks are also object. Whether they are implemented as mutex or semaphore is an implementation detail. The interface remains the same.
Give it some thought!
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.