nanogui: multithread question


Previous by date: 17 May 2001 00:57:09 -0000 Re: GTK+ port to nano-X, Alan Cox
Next by date: 17 May 2001 00:57:09 -0000 Re: MicroWindows' IPC?, PcHome
Previous in thread:
Next in thread: 17 May 2001 00:57:09 -0000 Re: multithread question, Jordan Crouse

Subject: multithread question
From: "hongouyang" ####@####.####
Date: 17 May 2001 00:57:09 -0000
Message-Id: <002a01c0de6c$47bbd420$557e9684@sttri.com>

Hello, every one.
I am using flnx0.16 and I attemp to make multithread work on it. I want to make a thread show the time on the gui every one second and I used the threadcreate(...) api. But when I compile and link the programe with gcc, a error occured and said can not resolve the reference to threadcreate( ). Am I write wrong or the needed libary does not exixt? And this is the demo code.

#include <stdio.h>
#include <string.h>
#include <pthread.h>
#include <errno.h>

class A{
public:
 int a;
 pthread_t w_tid;
 pthread_t r_tid;
 void doit();
 void* writer(void* arg);
 void* reader(void* arg);
 A(){
  this->a = 0;
 }  
};

void* A::writer(void* arg){
 while(1)
  printf("thread writer: %d \n", this->a++);
 return NULL;
}

void* A::reader(void* arg){
 while(1)
  printf("thread reader: %d \n", this->a--);
 return NULL;
}

void A::doit(){
 pthread_create(&w_tid, NULL, &A::writer, NULL);
 pthread_create(&r_tid, NULL, &A::reader, NULL);
 pthread_join(w_tid, NULL);
 pthread_join(r_tid, NULL);
}

int main(int argc, char** argv){
 A*  aa = new A();
 aa->doit();
 return 0;
}

Another question. When I add a callback to the flnx button, the callback function must ba a static function in a class or a global function, or the program will cause segmentation fault when running.How does this happen?

Thanks in advance.

Previous by date: 17 May 2001 00:57:09 -0000 Re: GTK+ port to nano-X, Alan Cox
Next by date: 17 May 2001 00:57:09 -0000 Re: MicroWindows' IPC?, PcHome
Previous in thread:
Next in thread: 17 May 2001 00:57:09 -0000 Re: multithread question, Jordan Crouse


Powered by ezmlm-browse 0.20.