This commit is contained in:
Олег Бородин
2025-10-01 11:21:05 +02:00
commit 9abd8a5e19
50 changed files with 12685 additions and 0 deletions

60
works/server.c Normal file
View File

@@ -0,0 +1,60 @@
#include <pthread.h>
#include <stdbool.h>
#include <stdio.h>
#include <unistd.h>
#include <semaphore.h>
#include <stdatomic.h>
#include <waitgroup.h>
pthread_t thread;
atomic_bool thread_cancel;
wg_t wg;
void* thread_run(void*);
int server_init(void) {
int res = 0;
thread_cancel = false;
wg_init(&wg);
pthread_attr_t attr;
pthread_attr_init(&attr);
pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
wg_add(&wg);
pthread_create(&thread, &attr, thread_run, NULL);
pthread_attr_destroy(&attr);
return res;
}
int server_run(void) {
int res = 0;
void *retval;
printf("server run\n");
sleep(4);
thread_cancel = true;
printf("thread cancel\n");
wg_wait(&wg);
printf("exit\n");
return res;
}
void* thread_run(void*) {
for(;;) {
if (thread_cancel == true) {
printf("thread canceled\n");
sleep(1);
wg_done(&wg);
return NULL;
}
printf("thread run\n");
sleep(1);
}
return NULL;
}

9
works/server.h Normal file
View File

@@ -0,0 +1,9 @@
#ifndef SERVER_H_QWERTY
#define SERVER_H_QWERTY
int server_init(void);
int server_run(void);
#endif