Code Monkey home page Code Monkey logo

philosophers's Introduction

Philosophers| 42 project| Threads and Mutex

#include <pthread.h>

General Thread Functions

pthread_join is waiting for a thread to teminate, collecting return value as a string inside retval pointer, on success - NULL is returned.

int pthread_join(pthread_t thread, void **retval)

pthread_create starts a new thread, thread returns thread ID, attr can be NULL for default, void * (*start_routine) pointer to function which takes void *, arg is argument for the function

int pthread_create(pthread_t *restrict thread, const pthread_attr_t *restrict attr, void *(*start_routine)(void *), void *restrict arg);

pthread_detach marks the thread as detached, which means its resources are released to the system, with no need to pthread_join, returns 0 or errno

int pthread_detach(pthread_t thread);

Mutex Functions

pthread_mutex_init - attr = NULL for default, makes mutex initialized and unlocked

int pthread_mutex_init(pthread_mutex_t *restrict mutex, const pthread_mutexattr_t *restrict attr);

pthread_mutex_destroy - it's only safe to destroy (make uninitialized) an initialized mutex that is unlocked

int pthread_mutex_destroy(pthread_mutex_t *mutex);

pthread_mutex_lock

int pthread_mutex_lock(pthread_mutex_t *mutex); pthread_mutex_unlock int pthread_mutex_unlock(pthread_mutex_t *mutex);

Other unknown functions

gettimeofday

int gettimeofday(struct timeval *restrict tv, struct timezone *_Nullable restrict tz);

struct timeval { time_t tv_sec; /* seconds / suseconds_t tv_usec; / microseconds */ };

struct timezone { int tz_minuteswest; /* minutes west of Greenwich / int tz_dsttime; / type of DST correction */ };

usleep - stop thread execution of the thread for min usec microseconds, 0 on success, -1 on err.

int usleep(useconds_t usec);

Sources

TO-DO List

  • learn how new functions for threads and thread lock work
  • learn about Dining Philosophers problem
  • write a draft for my Philo solution
  • check the coded C solutions available
  • modify the draft of my solution

philosophers's People

Contributors

marianne-p avatar

Watchers

 avatar

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.