![]() |
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
#11 |
|
Professional Programmer
|
Care to share how you fixed it and perhaps a peek at the working code?
__________________
Amateurs built the ark Professionals built the Titanic |
|
|
|
|
|
#12 |
|
Professional Programmer
Join Date: Jan 2007
Location: Cape Town
Posts: 291
Rep Power: 2
![]() |
no problem!
#include <iostream>
using namespace std;
#include <pthread.h>
class Thread {
public:
//
Thread() {}
virtual ~Thread() {}
void start() {
if(pthread_create(&thread,0,&(Thread::func),this) != 0) {
cerr << "error: could not create thread" << endl;
exit(0);
}
}
void join() {
if(pthread_join(thread,0) != 0) {
cerr << "error: could not join thread" << endl;
exit(0);
}
}
private:
//
static void *func(void *arg) {
Thread *thd = reinterpret_cast<Thread *>(arg);
if(thd)
thd->execute();
return (void *)0;
}
pthread_t thread;
protected:
virtual void execute() = 0;
};
class TestThread : public Thread {
public:
TestThread() {}
~TestThread() {}
protected:
void execute() {
cout << "Running Test thread..." << endl;
for(int i=0; i<5; i++) {
cout << "working..." << endl;
sleep(1);
}
cout << "done..." << endl;
}
};
int main() {
//
TestThread thd;
thd.start();
thd.join();
return 0;
}hope it helps ![]() |
|
|
|
|
|
#13 |
|
Professional Programmer
Join Date: Jan 2007
Location: Cape Town
Posts: 291
Rep Power: 2
![]() |
heya! im back!
ive got the port working fine for threads, mutex and semaphores... however im having trouble wrapping my head around the threadpool, mainly the synchronization problems... can anyone provide a url to some theory, design etc? ive googled all over but nada ![]() thanks ![]() |
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| problem with node implementation | brad sue | C++ | 12 | Mar 4th, 2007 11:27 PM |
| Accessing another thread | BlazingWolf | C# | 2 | Apr 19th, 2006 4:19 PM |
| threads | jayme | C++ | 21 | Jan 28th, 2006 10:20 PM |
| CPU Usage goes to 100% when pthread_cond_wait is being used | zen_buddha | C++ | 1 | Oct 13th, 2005 5:59 AM |
| Passing array as argument to a thread | Symptom | C | 5 | Sep 30th, 2005 6:52 PM |