Структура epoll сервера
Форум — Development
Имеет ли такая конструкция право на существование?
main.cpp
#include <stdio.h>
#include <iostream>
#include "core.h"
CCore *core;
int main()
{
core = new CCore();
CoreThreadStart(core);
delete core;
return 0;
}
core.h
#ifndef CORE_H
#define CORE_h
#include <stdio.h>
#include <stdlib.h>
#include <pthread.h>
class CCore
{
public:
CCore();
void listen();
void worker();
void data();
static pthread_mutex_t mutex;
};
bool CoreThreadStart(CCore *core);
#endif
core.cpp
#include "core.h"
pthread_mutex_t CCore::mutex;
CCore::CCore()
{
pthread_mutex_init(&mutex, NULL);
}
void *WorkerTh(void* param)
{
CCore *a = (CCore*)param;
a->worker();
return 0;
}
void *ListnerTh(void* param)
{
CCore *a = (CCore*)param;
a->listen();
return 0;
}
void *DataTh(void* param)
{
CCore *a = (CCore*)param;
a->data();
return 0;
}
bool CoreThreadStart(CCore *core)
{
pthread_t th;
pthread_create(&th, NULL, &ListnerTh, (void*)core);
pthread_create(&th, NULL, &WorkerTh, (void*)core);
pthread_create(&th, NULL, &DataTh, (void*)core);
return true;
}
void CCore::listen()
{
pthread_mutex_lock(&mutex);
printf("Listner\n");
pthread_mutex_unlock(&mutex);
}
void CCore::worker()
{
pthread_mutex_lock(&mutex);
printf("Worker\n");
pthread_mutex_unlock(&mutex);
}
void CCore::data()
{
pthread_mutex_lock(&mutex);
printf("Data\n");
pthread_mutex_unlock(&mutex);
}