add maybe work create mutex and getfork for philo
This commit is contained in:
parent
709288b773
commit
7790cc4944
2
.vscode/configurationCache.log
vendored
2
.vscode/configurationCache.log
vendored
@ -1 +1 @@
|
||||
{"buildTargets":["all"],"launchTargets":[],"customConfigurationProvider":{"workspaceBrowse":{"browsePath":[],"compilerArgs":[]},"fileIndex":[]}}
|
||||
{"buildTargets":[],"launchTargets":[],"customConfigurationProvider":{"workspaceBrowse":{"browsePath":[],"compilerArgs":[]},"fileIndex":[]}}
|
||||
9
.vscode/dryrun.log
vendored
9
.vscode/dryrun.log
vendored
@ -1,6 +1,7 @@
|
||||
make all --dry-run --keep-going --print-directory
|
||||
make: Entering directory `/Users/denisnadey/Desktop/Project/с/Philosophers'
|
||||
make: Leaving directory `/Users/denisnadey/Desktop/Project/с/Philosophers'
|
||||
make --dry-run --always-make --keep-going --print-directory
|
||||
make: Entering directory `/Users/mdenys/Desktop/projects/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
16
.vscode/launch.json
vendored
Normal 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
84
.vscode/targets.log
vendored
@ -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
|
||||
|
||||
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
|
||||
|
||||
@ -28,27 +25,30 @@ VSCODE_LOG_NATIVE = false
|
||||
# automatic
|
||||
@F = $(notdir $@)
|
||||
# makefile
|
||||
CURDIR := /Users/denisnadey/Desktop/Project/с/Philosophers
|
||||
CURDIR := /Users/mdenys/Desktop/projects/philosophers
|
||||
# makefile
|
||||
SHELL = /bin/sh
|
||||
# environment
|
||||
VSCODE_NLS_CONFIG = {"locale":"ru","availableLanguages":{},"_languagePackSupport":true}
|
||||
VSCODE_NLS_CONFIG = {"locale":"en-us","availableLanguages":{},"_languagePackSupport":true}
|
||||
# environment
|
||||
_ = /usr/bin/make
|
||||
# makefile
|
||||
MAKEFILE_LIST :=
|
||||
# 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
|
||||
VSCODE_VERBOSE_LOGGING = true
|
||||
# environment
|
||||
__CFBundleIdentifier = com.microsoft.VSCode
|
||||
# environment
|
||||
VSCODE_IPC_HOOK_EXTHOST = /var/folders/kq/kc3pf_ns62n6hc7n74119qf00000gn/T/vscode-ipc-d8ce7923-f56f-4eb9-b774-6248ac64f344.sock
|
||||
VSCODE_IPC_HOOK_EXTHOST = /var/folders/zz/zyxvpxvq6csfxvn_n003vhs000yw68/T/vscode-ipc-5e87255d-4c59-4ce0-938f-d9af1a63e1c5.sock
|
||||
# environment
|
||||
VSCODE_CWD = /
|
||||
# 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
|
||||
VSCODE_LOG_STACK = false
|
||||
# environment
|
||||
@ -56,23 +56,25 @@ ELECTRON_RUN_AS_NODE = 1
|
||||
# default
|
||||
.FEATURES := target-specific order-only second-expansion else-if archives jobserver check-symlink
|
||||
# environment
|
||||
SSH_AUTH_SOCK = /private/tmp/com.apple.launchd.F5MO7Kk0sJ/Listeners
|
||||
SSH_AUTH_SOCK = /private/tmp/com.apple.launchd.HmOvHs1Y9f/Listeners
|
||||
# automatic
|
||||
%F = $(notdir $%)
|
||||
# environment
|
||||
HOMEBREW_TEMP = /tmp/mdenys/Homebrew/Temp
|
||||
# environment
|
||||
VSCODE_PIPE_LOGGING = true
|
||||
# environment
|
||||
PWD = /Users/denisnadey/Desktop/Project/с/Philosophers
|
||||
PWD = /Users/mdenys/Desktop/projects/philosophers
|
||||
# environment
|
||||
ORIGINAL_XDG_CURRENT_DESKTOP = undefined
|
||||
# environment
|
||||
VSCODE_AMD_ENTRYPOINT = vs/workbench/services/extensions/node/extensionHostProcess
|
||||
# environment
|
||||
HOME = /Users/denisnadey
|
||||
HOME = /Users/mdenys
|
||||
# default
|
||||
MAKEFILEPATH := /Applications/Xcode.app/Contents/Developer/Makefiles
|
||||
# environment
|
||||
LOGNAME = denisnadey
|
||||
LOGNAME = mdenys
|
||||
# environment
|
||||
APPLICATION_INSIGHTS_NO_DIAGNOSTIC_CHANNEL = true
|
||||
# environment
|
||||
@ -81,31 +83,40 @@ VSCODE_HANDLES_UNCAUGHT_ERRORS = true
|
||||
^D = $(patsubst %/,%,$(dir $^))
|
||||
# environment
|
||||
XPC_FLAGS = 0x0
|
||||
# environment
|
||||
COLORTERM = truecolor
|
||||
# default
|
||||
MAKE = $(MAKE_COMMAND)
|
||||
# default
|
||||
MAKECMDGOALS := all
|
||||
# environment
|
||||
SHLVL = 1
|
||||
LC_TERMINAL = iTerm2
|
||||
# environment
|
||||
HOMEBREW_CACHE = /tmp/mdenys/Homebrew/Caches
|
||||
# environment
|
||||
SHLVL = 2
|
||||
# default
|
||||
MAKE_VERSION := 3.81
|
||||
# environment
|
||||
USER = denisnadey
|
||||
USER = mdenys
|
||||
# makefile
|
||||
.DEFAULT_GOAL :=
|
||||
# default
|
||||
MAKECMDGOALS := all
|
||||
# environment
|
||||
TERM_SESSION_ID = w0t0p0:520B77F0-CFEA-4D37-8A86-B45CDD412BEF
|
||||
# automatic
|
||||
%D = $(patsubst %/,%,$(dir $%))
|
||||
# default
|
||||
|
||||
MAKE_COMMAND := /Applications/Xcode.app/Contents/Developer/usr/bin/make
|
||||
# environment
|
||||
TERM_PROGRAM = iTerm.app
|
||||
# default
|
||||
.VARIABLES :=
|
||||
# environment
|
||||
TMPDIR = /var/folders/kq/kc3pf_ns62n6hc7n74119qf00000gn/T/
|
||||
TMPDIR = /var/folders/zz/zyxvpxvq6csfxvn_n003vhs000yw68/T/
|
||||
# automatic
|
||||
*F = $(notdir $*)
|
||||
# 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
|
||||
MAKEFLAGS = Rrqp
|
||||
# environment
|
||||
@ -113,33 +124,45 @@ MFLAGS = -Rrqp
|
||||
# automatic
|
||||
*D = $(patsubst %/,%,$(dir $*))
|
||||
# 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
|
||||
+D = $(patsubst %/,%,$(dir $+))
|
||||
# automatic
|
||||
+F = $(notdir $+)
|
||||
# environment
|
||||
__CF_USER_TEXT_ENCODING = 0x1F5:0x7:0x31
|
||||
ITERM_SESSION_ID = w0t0p0:520B77F0-CFEA-4D37-8A86-B45CDD412BEF
|
||||
# environment
|
||||
COMMAND_MODE = unix2003
|
||||
COLORFGBG = 7;0
|
||||
# environment
|
||||
__CF_USER_TEXT_ENCODING = 0xF70C8:0x0:0x0
|
||||
# default
|
||||
MAKEFILES :=
|
||||
# automatic
|
||||
<F = $(notdir $<)
|
||||
# environment
|
||||
ITERM_PROFILE = Default
|
||||
# environment
|
||||
LC_ALL = C
|
||||
# automatic
|
||||
^F = $(notdir $^)
|
||||
# default
|
||||
SUFFIXES :=
|
||||
# default
|
||||
.INCLUDE_DIRS = /usr/local/include
|
||||
# environment
|
||||
MAKELEVEL := 0
|
||||
# environment
|
||||
LANG = C
|
||||
# environment
|
||||
VSCODE_PID = 20943
|
||||
TERM = xterm-256color
|
||||
# environment
|
||||
VSCODE_PID = 96474
|
||||
# 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
|
||||
|
||||
@ -147,9 +170,9 @@ VSCODE_PID = 20943
|
||||
|
||||
# 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
|
||||
|
||||
@ -209,7 +232,6 @@ GNUmakefile:
|
||||
# Load=0/32=0%, Rehash=0, Collisions=0/0=0%
|
||||
|
||||
# files hash-table stats:
|
||||
|
||||
# Load=6/1024=1%, Rehash=0, Collisions=0/17=0%
|
||||
# VPATH Search Paths
|
||||
|
||||
@ -222,6 +244,6 @@ GNUmakefile:
|
||||
# strcache size: 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
|
||||
|
||||
|
||||
|
||||
@ -18,7 +18,7 @@ vpath %.c $(SRC_DIR)
|
||||
|
||||
CC = gcc
|
||||
RM = rm -f
|
||||
CFLAGS = -Wall -Wextra -Werror -I ./includes/
|
||||
CFLAGS = -g -Wall -Wextra -Werror -I ./includes/
|
||||
|
||||
NAME = philo_one
|
||||
|
||||
|
||||
@ -9,12 +9,18 @@
|
||||
# include <string.h>
|
||||
|
||||
|
||||
typedef struct s_philo
|
||||
{
|
||||
int right_fork;
|
||||
int left_fork;
|
||||
} t_philo;
|
||||
|
||||
typedef struct s_philo_data
|
||||
{
|
||||
pthread_mutex_t *mutex;
|
||||
t_philo *philors;
|
||||
} t_philo_data;
|
||||
|
||||
|
||||
typedef struct s_all
|
||||
{
|
||||
int number_of_philosophers;
|
||||
|
||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -34,11 +34,43 @@ int func_test(t_all *all)
|
||||
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 i;
|
||||
|
||||
i = 0;
|
||||
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);
|
||||
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)
|
||||
|
||||
10
workspace.code-workspace
Normal file
10
workspace.code-workspace
Normal file
@ -0,0 +1,10 @@
|
||||
{
|
||||
"folders": [
|
||||
{
|
||||
"path": "."
|
||||
},
|
||||
{
|
||||
"path": "."
|
||||
}
|
||||
]
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user