Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Jul 17th, 2007, 10:25 AM   #11
peace_of_mind
Professional Programmer
 
peace_of_mind's Avatar
 
Join Date: Sep 2004
Location: Hell if I know most of the time
Posts: 439
Rep Power: 5 peace_of_mind is on a distinguished road
Send a message via MSN to peace_of_mind Send a message via Yahoo to peace_of_mind
Care to share how you fixed it and perhaps a peek at the working code?
__________________
Amateurs built the ark
Professionals built the Titanic

peace_of_mind is offline   Reply With Quote
Old Jul 17th, 2007, 10:44 AM   #12
rwm
Professional Programmer
 
Join Date: Jan 2007
Location: Cape Town
Posts: 291
Rep Power: 2 rwm is on a distinguished road
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
rwm is offline   Reply With Quote
Old Jul 23rd, 2007, 2:57 AM   #13
rwm
Professional Programmer
 
Join Date: Jan 2007
Location: Cape Town
Posts: 291
Rep Power: 2 rwm is on a distinguished road
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
rwm is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

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




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 2:50 AM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC