From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 24402 invoked by alias); 28 Jan 2009 01:28:03 -0000 Received: (qmail 24394 invoked by uid 22791); 28 Jan 2009 01:28:02 -0000 X-SWARE-Spam-Status: No, hits=3.2 required=5.0 tests=BAYES_50,DNS_FROM_OPENWHOIS,J_CHICKENPOX_33,SPF_HELO_PASS,SPF_PASS,WHOIS_MYPRIVREG X-Spam-Check-By: sourceware.org Received: from kuber.nabble.com (HELO kuber.nabble.com) (216.139.236.158) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Wed, 28 Jan 2009 01:27:57 +0000 Received: from isper.nabble.com ([192.168.236.156]) by kuber.nabble.com with esmtp (Exim 4.63) (envelope-from ) id 1LRzDf-00046n-SN for pthreads-win32@sourceware.org; Tue, 27 Jan 2009 17:27:55 -0800 Message-ID: <21698291.post@talk.nabble.com> Date: Wed, 28 Jan 2009 01:28:00 -0000 From: gcherian To: pthreads-win32@sourceware.org Subject: Re: Trying to develop a pool executor from pthreads... in C++ In-Reply-To: <61e59ce30710120512i40fd0912t1df90a33c59e9f26@mail.gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit References: <61e59ce30710120512i40fd0912t1df90a33c59e9f26@mail.gmail.com> X-IsSubscribed: yes Mailing-List: contact pthreads-win32-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: pthreads-win32-owner@sourceware.org X-SW-Source: 2009/txt/msg00000.txt.bz2 Hello, Runner class should be inheriting the Runnable (to override the virtual run() method) -George Cherian mlnglstaccram alksjd wrote: > > For the sake of learning i am trying to develp a pool executor... but > it doesnt work.. can u ppl tell me where i am goin wrong? I am getting > an assertion failure in windows in the line below with comments, in > file PoolExecutor.h.. > > > /* > main.cpp > */ > #include > #include > #include > #include "PoolExecutor.h" > > > > using namespace std; > > class Runner{ > public: > Runner(){} > ~Runner(){} > void run(){ > for(int i=0;i<100;++i) > cout<<"i="< > #include > #include > > class PoolExecutor; > void *func(void *temp); > > class Runnable{ > public: > virtual void run()=0; > }; > > > class Thread{ > pthread_t threadId; > Runnable *runnable; > public: > Thread(){ > runnable=NULL; > } > > void start(PoolExecutor *pthRun){ > int started = pthread_create (&threadId, NULL, func, > pthRun); > std::cout<< started< } > > void join(){ > pthread_join(threadId,NULL); > } > > }; > > > > class PoolExecutor{ > Thread *threads; > int N; > bool cancelled ; > std::queue taskQueue; > pthread_mutex_t taskQueueMutex; > public: > PoolExecutor(int numberOfThreads){ > N=numberOfThreads; > if(numberOfThreads<=0 && numberOfThreads>512) > N=5; > cancelled= false; > pthread_mutex_init(&taskQueueMutex,NULL); > threads = new Thread[N]; > for(int i=0;i threads[i].start(this); > } > ~PoolExecutor(){ > cancelled = true; > for(int i=0;i threads[i].join(); > delete[] threads; > } > > void execute(Runnable* runnable ){ > pthread_mutex_lock(&taskQueueMutex); > taskQueue.push(runnable); > pthread_mutex_unlock(&taskQueueMutex); > } > > void* runMethod(void * param){ > for(;;){ > while(taskQueue.empty()&& !cancelled){ > Sleep(100); > } > if(cancelled){ > return NULL; > } > pthread_mutex_lock(&taskQueueMutex); > if(taskQueue.empty()){ > pthread_mutex_unlock(&taskQueueMutex); > continue; > } > Runnable *runnable = (Runnable *)taskQueue.front(); > //////////////////////////////////////////////////////////////////////////////////////////////// > //////////////////////////////////// i get error in the above line > //////////////////////////////////////////////////////////////////////////////////////////////// > taskQueue.pop(); > pthread_mutex_unlock(&taskQueueMutex); > runnable->run(); > delete runnable; > if(cancelled){ > return NULL; > } > } > return NULL; > } > > }; > > void *func(void *temp){ > PoolExecutor *poolExecutor = (PoolExecutor *)temp; > return poolExecutor->runMethod(NULL); > } > > Thanks > > -- View this message in context: http://www.nabble.com/Trying-to-develop-a-pool-executor-from-pthreads...-in-C%2B%2B-tp13174112p21698291.html Sent from the Sourceware - pthreads-win32 list mailing list archive at Nabble.com.