i have a main thread which should have 3 different threads
receive thread – which receives data using sockets
process thread – process the receive data
display thread – display it on gui
thing is when some message is received then i shud send pthread_kill to my process thread then only it shud process the message
i don’ t have an idea of pthreads and signals in c++
and i was told to use c++ calls only
i have written the program like this
and am getting segmentation fault
can any body suggest me how to solve and continue this
#include<iostream>
#include <stdio.h>
#include <stdlib.h>
#include <pthread.h>
#include "structures.h"
#include <string.h>
#include <unistd.h>
#include <stdio.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <sys/types.h>
#include <arpa/inet.h>
#include <fcntl.h>
#include <signal.h>
#include <check.h>
#define MAX_DATA_SIZE 512
using namespace std;
pthread_t receive_thread,process_thread;
void sig_handler(int sig)
{
cout<<"caught signal"<<sig<<endl;
}
void *receive_data(void *)
{
cout<<"Receive thread is running"<<endl;
pthread_kill(process_thread,SIGUSR1);
return 0;
}
void *process_data(void*)
{
cout<<"process thread is running"<<endl;
struct sigaction sa;
sigemptyset(&sa.sa_mask);
sa.sa_flags = 0;
sa.sa_handler = sig_handler;
sigaction(SIGUSR1,&sa,NULL);
pthread_exit(0);
return 0;
}
int main(void)
{
int receive_status,process_status;
receive_status=pthread_create(&receive_thread,NULL,receive_data,NULL); // Create Thread
pthread_join(receive_thread,NULL); // Parent waits for
process_status = pthread_create (&process_thread,NULL,process_data,NULL);
//pthread_join(process_thread,NULL);
return 0;
}
↧