create logic block

This commit is contained in:
Denis 2021-05-11 17:26:54 +03:00
parent cb914510d5
commit fb7985cb67
8 changed files with 54 additions and 5 deletions

View File

@ -1,6 +1,6 @@
.PHONY: all clean fclean re .PHONY: all clean fclean re
SRCS = main.c utilc.c parser.c SRCS = main.c utilc.c parser.c logic.c
SRC_DIR = ./srcs/ SRC_DIR = ./srcs/
@ -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 = -Wall -Wextra -Werror -I ./includes/
NAME = philo_one NAME = philo_one
@ -31,13 +31,13 @@ $(OBJ_DIR):
mkdir -p obj mkdir -p obj
$(NAME): $(OBJS_FILES) $(NAME): $(OBJS_FILES)
$(CC) $(CFLAGS) -o $(NAME) $(OBJS_FILES) $(CC) $(CFLAGS) -o $(NAME) $(OBJS_FILES) -lpthread
clean: clean:
$(RM) $(OBJS_FILES) $(RM) $(OBJS_FILES)
$(OBJ_DIR)%.o: %.c $(HEADER) $(OBJ_DIR)%.o: %.c $(HEADER)
$(CC) $(CFLAGS) -c $< -o $@ $(CC) $(CFLAGS) -c $< -o $@
fclean: clean fclean: clean
$(RM) $(NAME) $(RM) $(NAME)

View File

@ -23,5 +23,6 @@ t_all *structalloc_and_bzero(void);
int parse_and_check_values(char **argv, int quantity); int parse_and_check_values(char **argv, int quantity);
int ft_atoi(const char *str); int ft_atoi(const char *str);
int check_f(char ch); int check_f(char ch);
int runner(t_all *all, int optional);
#endif #endif

BIN
philo_one/obj/logic.o Normal file

Binary file not shown.

Binary file not shown.

Binary file not shown.

47
philo_one/srcs/logic.c Normal file
View File

@ -0,0 +1,47 @@
#include "../includes/philo_header.h"
void *test(char *str)
{
printf("поток %s отработал\n", str);
return(NULL);
}
int func_test(t_all *all)
{
pthread_t t0;
pthread_t t1;
void *result;
(void)all;
if (pthread_create(&t0, NULL, (void*)test, "t0") == -1) // предпоследнее это функция и аргумент
{
printf("не могу создать поток t0\n");
}
if (pthread_create(&t1, NULL, (void*)test, "t1") == -1) // предпоследнее это функция и аргумент
{
printf("не могу создать поток t1\n");
}
if (pthread_join(t0, &result) == -1)
{
printf("не могу присоединиться к потоку t0\n");
}
if (pthread_join(t1, &result) == -1)
{
printf("не могу присоединиться к потоку t1\n");
}
return (0);
}
int runner(t_all *all, int optional)
{
if (optional)
{
func_test(all);
return(0);
}
else
{
return(1);
}
}

View File

@ -9,6 +9,5 @@ int main(int argc, char **argv)
printf("exit because error\n"); printf("exit because error\n");
return (1); return (1);
} }
return(0); return(0);
} }

View File

@ -60,6 +60,7 @@ int parse_and_check_values(char **argv, int quantity)
if (!parse_param(all, 0, argv)) if (!parse_param(all, 0, argv))
{ {
printf("ok standart run\n"); printf("ok standart run\n");
runner(all, 0);
return(1); return(1);
} }
else else
@ -73,6 +74,7 @@ int parse_and_check_values(char **argv, int quantity)
if (!parse_param(all, 1, argv)) if (!parse_param(all, 1, argv))
{ {
printf("ok run with optional\n"); printf("ok run with optional\n");
runner(all, 1);
return(1); return(1);
} }
else else