Structural deformable models
Public Member Functions | Static Public Member Functions | Friends | List of all members
vuThread Class Referenceabstract

#include <vuThread.h>

Inheritance diagram for vuThread:
Inheritance graph
[legend]

Public Member Functions

virtual ~vuThread ()
 Virtual destructor (doing nothing) More...
 
bool startThread (int whatsup, void *data=NULL)
 
virtual void run (int whatsup, void *data)=0
 
void stopThread ()
 

Static Public Member Functions

static void usleep (unsigned long ms)
 sleep for n microseconds (!!not yet implemented for win32) More...
 

Friends

void * _kickoff (void *ptr)
 

Detailed Description

class providing basic multithreading functions

NB - These threads are created as detached threads so that they will deallocate properely as the vuThread class is currently used.

Definition at line 79 of file vuThread.h.

Constructor & Destructor Documentation

virtual vuThread::~vuThread ( )
inlinevirtual

Virtual destructor (doing nothing)

Definition at line 83 of file vuThread.h.

References _kickoff(), and NULL.

83 {};

Member Function Documentation

virtual void vuThread::run ( int  whatsup,
void *  data 
)
pure virtual

This function is called when a new thread is started by startThread. The function is virtual. Override it to run your own code. The whatsup argument is for free use to customize behaviour of different threads.

Implemented in Brain.

Referenced by _kickoff(), and vuMutex::unlock().

bool vuThread::startThread ( int  whatsup,
void *  data = NULL 
)

This function is called by the user to start a new thread. It calls the virtual run() with parameter whatsup to allow different behaviour of the threads.

Definition at line 45 of file vuThread.cpp.

References _kickoff(), and NULL.

Referenced by Brain::Brain(), Brain::doCommand(), and vuMutex::unlock().

47 {
48  pthread_t *thread = new pthread_t;
49 
50  m_WhatsupMutex.lock();
51  m_Whatsup = whatsup;
52  m_AdditionalData = data;
53 
54  pthread_attr_t tattr;
55 
56 // cout << "here" << endl;
57 
58  pthread_attr_setdetachstate (&tattr, PTHREAD_CREATE_DETACHED);
59 
60 // cout << "s1" << endl;
61 
62  int t = pthread_create(thread, NULL, &_kickoff, (void*) this);
63 
64  if (t != 0)
65 
66  {
67 // cout << "s2.5" << endl;
68  cout << strerror (errno) << endl;
69  if (t == EAGAIN)
70  cout << "eagain" << endl;
71 
72  return false;
73  }
74 
75  pthread_detach (*thread);
76 
77 // cout << "s3" << endl;
78 
79  return true;
80 }
#define NULL
Definition: simpletypes.h:9
friend void * _kickoff(void *ptr)
Definition: vuThread.cpp:20
void lock()
Definition: vuThread.cpp:138
void vuThread::stopThread ( )

Definition at line 107 of file vuThread.cpp.

References NULL.

Referenced by _kickoff(), and vuMutex::unlock().

108 {
109  pthread_exit(NULL);
110 }
#define NULL
Definition: simpletypes.h:9
void vuThread::usleep ( unsigned long  ms)
static

sleep for n microseconds (!!not yet implemented for win32)

Definition at line 112 of file vuThread.cpp.

Referenced by Brain::run(), and vuMutex::unlock().

113 {
114  ::usleep(ms);
115 }
static void usleep(unsigned long ms)
sleep for n microseconds (!!not yet implemented for win32)
Definition: vuThread.cpp:112

Friends And Related Function Documentation

void* _kickoff ( void *  ptr)
friend

Definition at line 20 of file vuThread.cpp.

21 {
22  vuThread *th = (vuThread*)ptr;
23  int whatsup = th->m_Whatsup;
24  void* data = th->m_AdditionalData;
25  th->m_WhatsupMutex.unlock();
26 
27  th->run(whatsup, data);
28 
29  th->stopThread();
30  return NULL;
31 }
#define NULL
Definition: simpletypes.h:9
void stopThread()
Definition: vuThread.cpp:107
virtual void run(int whatsup, void *data)=0
void unlock()
Definition: vuThread.cpp:148

The documentation for this class was generated from the following files: