dumay, dima, dumay

This commit is contained in:
ada-dmitry
2023-11-22 00:04:41 +03:00
parent 53b1c06aa9
commit 7d0d3ea7c5
9 changed files with 35 additions and 43 deletions
+6
View File
@@ -0,0 +1,6 @@
{
"files.associations": {
"head.h": "c",
"unistd.h": "c"
}
}
+13 -15
View File
@@ -1,8 +1,7 @@
#include <stdio.h>
#include <math.h>
#include <signal.h>
#include <unistd.h>
#include <pthread.h>
#include <math.h>
double f(double x)
{
@@ -19,20 +18,19 @@ void find_zero(double *pa, double *pb, double eps, double *px)
printf("Текущее приближение: %lf\n", *px);
}
void ctrlc_handler(int signum)
{
int sig;
sigset_t *set = (sigset_t *)signum;
while (1)
{
sigwait(set, &sig);
if (sig == SIGINT)
void ctrlc_handler(int signum, char *ch)
{
printf("\nПолучен сигнал Ctrl+C\n");
printf("Продолжить поиск корня? (C - продолжить, A - закончить работу программы, R - начать поиск на другом отрезке): ");
printf("\nПродолжить поиск корня? (C - продолжить, A - закончить работу программы, R - начать поиск на другом отрезке): \n");
}
}
}
// void choose_path(char *choice);
// void choose_path()
// {
// char choice = getchar();
// if(choice == 'A')
// break;
// else if(choice == 'C')
// find_zero()
// }
// void new_row(double *pa, double *pb);
+15 -27
View File
@@ -1,53 +1,41 @@
#include <stdio.h>
#include <signal.h>
#include <unistd.h>
#include <pthread.h>
#include <math.h>
double f(double x); // function x
void find_zero(double *pa, double *pb, double eps, double *px); //
void ctrlc_handler(int signum);
// void choose_path(char *choice);
// void new_row(double *pa, double *pb);
double f(double x);
void find_zero(double *pa, double *pb, double eps, double *px);
void ctrlc_handler(int signum, char *ch);
void choose_path();
void new_row(double *pa, double *pb);
int main()
{
double a, b, eps, x, *pa = &a, *pb = &b, *px = &x;
char choice = ' ', *ch = &choice;
pthread_t thread;
sigset_t set;
char choice, *ch = &choice;
struct sigaction sa;
sa.sa_handler = ctrlc_handler(, ch);
sa.sa_flags = 0;
sigemptyset(&sa.sa_mask);
printf("Введите интервал [a, b] и точность eps: ");
scanf("%lf %lf %lf", pa, pb, &eps);
find_zero(pa, pb, eps, px);
// Создание набора сигналов и добавление в него SIGINT
sigemptyset(&set);
sigaddset(&set, SIGINT);
// Блокировка сигналов в наборе для основного потока
if (pthread_sigmask(SIG_BLOCK, &set, NULL) != 0)
if (sigaction(SIGINT, &sa, NULL) == -1)
{
perror("pthread_sigmask");
return 1;
}
// Создание потока для обработчика сигнала
if (pthread_create(&thread, NULL, ctrlc_handler, &set) != 0)
{
perror("pthread_create");
perror("sigaction");
return 1;
}
printf("Ожидание сигнала Ctrl+C...\n");
find_zero(pa, pb, eps, px);
while (1)
{
sleep(1);
}
signal(SIGINT, ctrlc_handler);
printf("Корень уравнения: %lf\n", *px);
printf("\nКорень уравнения: %lf\n", *px);
printf("Работа программы завершена.\n");
return 0;
Binary file not shown.
BIN
View File
Binary file not shown.
View File
View File
View File