add maybe work create mutex and getfork for philo

This commit is contained in:
Matthos Denys 2021-05-12 17:40:56 +03:00
parent 709288b773
commit 7790cc4944
13 changed files with 125 additions and 38 deletions

View File

@ -1 +1 @@
{"buildTargets":["all"],"launchTargets":[],"customConfigurationProvider":{"workspaceBrowse":{"browsePath":[],"compilerArgs":[]},"fileIndex":[]}} {"buildTargets":[],"launchTargets":[],"customConfigurationProvider":{"workspaceBrowse":{"browsePath":[],"compilerArgs":[]},"fileIndex":[]}}

9
.vscode/dryrun.log vendored
View File

@ -1,6 +1,7 @@
make all --dry-run --keep-going --print-directory make --dry-run --always-make --keep-going --print-directory
make: Entering directory `/Users/denisnadey/Desktop/Project/с/Philosophers' make: Entering directory `/Users/mdenys/Desktop/projects/philosophers'
make: Leaving directory `/Users/denisnadey/Desktop/Project/с/Philosophers'
make: *** No rule to make target `all'. make: Leaving directory `/Users/mdenys/Desktop/projects/philosophers'
make: *** No targets specified and no makefile found. Stop.

16
.vscode/launch.json vendored Normal file
View File

@ -0,0 +1,16 @@
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"type": "lldb",
"request": "launch",
"name": "Debug",
"program": "${workspaceFolder}/philo_one/philo_one",
"args": ["5", "1", "1", "1", "1"],
"cwd": "${workspaceFolder}"
}
]
}

84
.vscode/targets.log vendored
View File

@ -7,11 +7,8 @@ make all --print-data-base --no-builtin-variables --no-builtin-rules --question
# This program built for i386-apple-darwin11.3.0 # This program built for i386-apple-darwin11.3.0
make: *** No rule to make target `all'. Stop.
# Make data base, printed on Sun May 9 12:20:42 2021 # Make data base, printed on Wed May 12 17:25:51 2021
# Variables # Variables
@ -28,27 +25,30 @@ VSCODE_LOG_NATIVE = false
# automatic # automatic
@F = $(notdir $@) @F = $(notdir $@)
# makefile # makefile
CURDIR := /Users/denisnadey/Desktop/Project/с/Philosophers CURDIR := /Users/mdenys/Desktop/projects/philosophers
# makefile # makefile
SHELL = /bin/sh SHELL = /bin/sh
# environment # environment
VSCODE_NLS_CONFIG = {"locale":"ru","availableLanguages":{},"_languagePackSupport":true} VSCODE_NLS_CONFIG = {"locale":"en-us","availableLanguages":{},"_languagePackSupport":true}
# environment # environment
_ = /usr/bin/make _ = /usr/bin/make
# makefile # makefile
MAKEFILE_LIST := MAKEFILE_LIST :=
# environment # environment
VSCODE_NODE_CACHED_DATA_DIR = /Users/denisnadey/Library/Application Support/Code/CachedData/cfa2e218100323074ac1948c885448fdf4de2a7f VSCODE_NODE_CACHED_DATA_DIR = /Users/mdenys/Library/Application Support/Code/CachedData/cfa2e218100323074ac1948c885448fdf4de2a7f
# environment # environment
VSCODE_VERBOSE_LOGGING = true VSCODE_VERBOSE_LOGGING = true
# environment # environment
__CFBundleIdentifier = com.microsoft.VSCode VSCODE_IPC_HOOK_EXTHOST = /var/folders/zz/zyxvpxvq6csfxvn_n003vhs000yw68/T/vscode-ipc-5e87255d-4c59-4ce0-938f-d9af1a63e1c5.sock
# environment
VSCODE_IPC_HOOK_EXTHOST = /var/folders/kq/kc3pf_ns62n6hc7n74119qf00000gn/T/vscode-ipc-d8ce7923-f56f-4eb9-b774-6248ac64f344.sock
# environment # environment
VSCODE_CWD = / VSCODE_CWD = /
# environment # environment
PATH = /usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/Library/Apple/usr/bin:/Users/denisnadey/development/flutter/bin:/opt/homebrew/bin Apple_PubSub_Socket_Render = /private/tmp/com.apple.launchd.EPpFRNecPx/Render
# environment
PATH = /Users/mdenys/.brew/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/munki:/Library/Frameworks/Mono.framework/Versions/Current/Commands:/Users/mdenys/.brew/bin
make: *** No rule to make target `all'. Stop.
# environment # environment
VSCODE_LOG_STACK = false VSCODE_LOG_STACK = false
# environment # environment
@ -56,23 +56,25 @@ ELECTRON_RUN_AS_NODE = 1
# default # default
.FEATURES := target-specific order-only second-expansion else-if archives jobserver check-symlink .FEATURES := target-specific order-only second-expansion else-if archives jobserver check-symlink
# environment # environment
SSH_AUTH_SOCK = /private/tmp/com.apple.launchd.F5MO7Kk0sJ/Listeners SSH_AUTH_SOCK = /private/tmp/com.apple.launchd.HmOvHs1Y9f/Listeners
# automatic # automatic
%F = $(notdir $%) %F = $(notdir $%)
# environment # environment
HOMEBREW_TEMP = /tmp/mdenys/Homebrew/Temp
# environment
VSCODE_PIPE_LOGGING = true VSCODE_PIPE_LOGGING = true
# environment # environment
PWD = /Users/denisnadey/Desktop/Project/с/Philosophers PWD = /Users/mdenys/Desktop/projects/philosophers
# environment # environment
ORIGINAL_XDG_CURRENT_DESKTOP = undefined ORIGINAL_XDG_CURRENT_DESKTOP = undefined
# environment # environment
VSCODE_AMD_ENTRYPOINT = vs/workbench/services/extensions/node/extensionHostProcess VSCODE_AMD_ENTRYPOINT = vs/workbench/services/extensions/node/extensionHostProcess
# environment # environment
HOME = /Users/denisnadey HOME = /Users/mdenys
# default # default
MAKEFILEPATH := /Applications/Xcode.app/Contents/Developer/Makefiles MAKEFILEPATH := /Applications/Xcode.app/Contents/Developer/Makefiles
# environment # environment
LOGNAME = denisnadey LOGNAME = mdenys
# environment # environment
APPLICATION_INSIGHTS_NO_DIAGNOSTIC_CHANNEL = true APPLICATION_INSIGHTS_NO_DIAGNOSTIC_CHANNEL = true
# environment # environment
@ -81,31 +83,40 @@ VSCODE_HANDLES_UNCAUGHT_ERRORS = true
^D = $(patsubst %/,%,$(dir $^)) ^D = $(patsubst %/,%,$(dir $^))
# environment # environment
XPC_FLAGS = 0x0 XPC_FLAGS = 0x0
# environment
COLORTERM = truecolor
# default # default
MAKE = $(MAKE_COMMAND) MAKE = $(MAKE_COMMAND)
# default
MAKECMDGOALS := all
# environment # environment
SHLVL = 1 LC_TERMINAL = iTerm2
# environment
HOMEBREW_CACHE = /tmp/mdenys/Homebrew/Caches
# environment
SHLVL = 2
# default # default
MAKE_VERSION := 3.81 MAKE_VERSION := 3.81
# environment # environment
USER = denisnadey USER = mdenys
# makefile # makefile
.DEFAULT_GOAL := .DEFAULT_GOAL :=
# default
MAKECMDGOALS := all
# environment
TERM_SESSION_ID = w0t0p0:520B77F0-CFEA-4D37-8A86-B45CDD412BEF
# automatic # automatic
%D = $(patsubst %/,%,$(dir $%)) %D = $(patsubst %/,%,$(dir $%))
# default # default
MAKE_COMMAND := /Applications/Xcode.app/Contents/Developer/usr/bin/make MAKE_COMMAND := /Applications/Xcode.app/Contents/Developer/usr/bin/make
# environment
TERM_PROGRAM = iTerm.app
# default # default
.VARIABLES := .VARIABLES :=
# environment # environment
TMPDIR = /var/folders/kq/kc3pf_ns62n6hc7n74119qf00000gn/T/ TMPDIR = /var/folders/zz/zyxvpxvq6csfxvn_n003vhs000yw68/T/
# automatic # automatic
*F = $(notdir $*) *F = $(notdir $*)
# environment # environment
VSCODE_IPC_HOOK = /Users/denisnadey/Library/Application Support/Code/1.56.0-main.sock VSCODE_IPC_HOOK = /Users/mdenys/Library/Application Support/Code/1.56.0-main.sock
# makefile # makefile
MAKEFLAGS = Rrqp MAKEFLAGS = Rrqp
# environment # environment
@ -113,33 +124,45 @@ MFLAGS = -Rrqp
# automatic # automatic
*D = $(patsubst %/,%,$(dir $*)) *D = $(patsubst %/,%,$(dir $*))
# environment # environment
XPC_SERVICE_NAME = application.com.microsoft.VSCode.3567092.3567098 TERM_PROGRAM_VERSION = 3.3.7
# environment
XPC_SERVICE_NAME = com.microsoft.VSCode.1224
# environment
LC_TERMINAL_VERSION = 3.3.7
# automatic # automatic
+D = $(patsubst %/,%,$(dir $+)) +D = $(patsubst %/,%,$(dir $+))
# automatic # automatic
+F = $(notdir $+) +F = $(notdir $+)
# environment # environment
__CF_USER_TEXT_ENCODING = 0x1F5:0x7:0x31 ITERM_SESSION_ID = w0t0p0:520B77F0-CFEA-4D37-8A86-B45CDD412BEF
# environment # environment
COMMAND_MODE = unix2003 COLORFGBG = 7;0
# environment
__CF_USER_TEXT_ENCODING = 0xF70C8:0x0:0x0
# default # default
MAKEFILES := MAKEFILES :=
# automatic # automatic
<F = $(notdir $<) <F = $(notdir $<)
# environment # environment
ITERM_PROFILE = Default
# environment
LC_ALL = C LC_ALL = C
# automatic # automatic
^F = $(notdir $^) ^F = $(notdir $^)
# default # default
SUFFIXES := SUFFIXES :=
# default
.INCLUDE_DIRS = /usr/local/include
# environment # environment
MAKELEVEL := 0 MAKELEVEL := 0
# environment # environment
LANG = C LANG = C
# environment # environment
VSCODE_PID = 20943 TERM = xterm-256color
# environment
VSCODE_PID = 96474
# variable set hash-table stats: # variable set hash-table stats:
# Load=61/1024=6%, Rehash=0, Collisions=1/81=1% # Load=73/1024=7%, Rehash=0, Collisions=4/94=4%
# Pattern-specific Variable Values # Pattern-specific Variable Values
@ -147,9 +170,9 @@ VSCODE_PID = 20943
# Directories # Directories
# . (device 16777231, inode 3623932): 10 files, no impossibilities. # . (device 16777227, inode 5034668): 7 files, no impossibilities.
# 10 files, no impossibilities in 1 directories. # 7 files, no impossibilities in 1 directories.
# Implicit Rules # Implicit Rules
@ -209,7 +232,6 @@ GNUmakefile:
# Load=0/32=0%, Rehash=0, Collisions=0/0=0% # Load=0/32=0%, Rehash=0, Collisions=0/0=0%
# files hash-table stats: # files hash-table stats:
# Load=6/1024=1%, Rehash=0, Collisions=0/17=0% # Load=6/1024=1%, Rehash=0, Collisions=0/17=0%
# VPATH Search Paths # VPATH Search Paths
@ -222,6 +244,6 @@ GNUmakefile:
# strcache size: total = 0 / max = 0 / min = 4096 / avg = 0 # strcache size: total = 0 / max = 0 / min = 4096 / avg = 0
# strcache free: total = 0 / max = 0 / min = 4096 / avg = 0 # strcache free: total = 0 / max = 0 / min = 4096 / avg = 0
# Finished Make data base on Sun May 9 12:20:42 2021 # Finished Make data base on Wed May 12 17:25:51 2021

View File

@ -18,7 +18,7 @@ vpath %.c $(SRC_DIR)
CC = gcc CC = gcc
RM = rm -f RM = rm -f
CFLAGS = -Wall -Wextra -Werror -I ./includes/ CFLAGS = -g -Wall -Wextra -Werror -I ./includes/
NAME = philo_one NAME = philo_one

View File

@ -9,12 +9,18 @@
# include <string.h> # include <string.h>
typedef struct s_philo
{
int right_fork;
int left_fork;
} t_philo;
typedef struct s_philo_data typedef struct s_philo_data
{ {
pthread_mutex_t *mutex; pthread_mutex_t *mutex;
t_philo *philors;
} t_philo_data; } t_philo_data;
typedef struct s_all typedef struct s_all
{ {
int number_of_philosophers; int number_of_philosophers;

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@ -34,11 +34,43 @@ int func_test(t_all *all)
return (0); return (0);
} }
void get_fork_for_philo(t_all *all)
{
int i;
i = 0;
while(i <= all->number_of_philosophers)
{
if (i == 0)
{
all->data_philo->philors[i].left_fork = all->number_of_philosophers;
all->data_philo->philors[i].right_fork = 0;
}
else
{
all->data_philo->philors[i].left_fork = i;
all->data_philo->philors[i].right_fork = i + 1;
}
i++;
}
}
int prepare_resources(t_all *all) int prepare_resources(t_all *all)
{ {
int i;
i = 0;
all->data_philo = ft_calloc(sizeof(t_philo_data), 1); all->data_philo = ft_calloc(sizeof(t_philo_data), 1);
all->data_philo->mutex = (pthread_mutex_t *)ft_calloc(sizeof(pthread_mutex_t), all->number_of_philosophers); all->data_philo->mutex = (pthread_mutex_t *)ft_calloc(sizeof(pthread_mutex_t), all->number_of_philosophers);
while (i < all->number_of_philosophers)
{
pthread_mutex_init(&all->data_philo->mutex[i], NULL);
i++;
}
all->data_philo->philors = (t_philo *)ft_calloc(sizeof(t_philo), all->number_of_philosophers);
get_fork_for_philo(all);
return (0);
} }
int runner(t_all *all, int optional) int runner(t_all *all, int optional)

10
workspace.code-workspace Normal file
View File

@ -0,0 +1,10 @@
{
"folders": [
{
"path": "."
},
{
"path": "."
}
]
}