[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-kimageshop
Subject:    Re: KImageShop on SMP machines, parallel machines or clusters
From:       Carsten Pfeiffer <carpdjih () cetus ! zrz ! TU-Berlin ! DE>
Date:       1999-07-25 20:56:49
[Download RAW message or body]

On Sun, Jul 25, 1999 at 09:05:23PM +0200, Matthias Elter wrote:

Hi,
 
> I second this. We should focus on a nice threading interface using user-level
> threads for now. We can still implement MPI later. We need a nice clean
> interface that hides the actual threading lib used. I'm going to start work on

ok, MPI can come later :o) For a first start, I'm attaching a qthread.h,
that Bavo De Ridder once posted to qt-interest. I don't know whether he
changed that in the meantime, but it looks like a good abstraction of any
thread-library.

> KImageShop after my exams on Wednesday. Hopefully Torben and Reggie finish
> their DOM hack until then.

Great. Hopefully Andrew is able to provide us with his current
canvas-widget by then.

Cheers,
Carsten Pfeiffer
-- 
http://www.geocities.com/SiliconValley/1632/

["qthread.h" (text/plain)]

/*
	This class contains common constants used in the QThread classes.
*/

class QThreadConst
{
public:

	typedef enum {
		CancelEnable  = PTHREAD_CANCEL_ENABLE,
		CancelDisable = PTHREAD_CANCEL_DISABLE
	} CancelState;

	typedef enum {
		CancelAsynchronous = PTHREAD_CANCEL_ASYNCHRONOUS,
		CancelDeferred     = PTHREAD_CANCEL_DEFERRED
	} CancelType;
};



/*
	This class containts functions that operate on the calling thread.
*/

class QThreadUtil
{
public:

	/*
		This function makes the calling thread sleep for the
		number of seconds
	*/
	static void sleep(unsigned int seconds);


	/*
		This function is identical except for the arguments it takes
	*/
	static void usleep(unsigned long microseconds);


	/*
		This function will yield the processor. The calling thread will
		be placed in the ready queue of the operating system and will
		compete for the next time slice. This function should be called
		during lengthy calculations to offer the cpu to other threads or
		processes.
	*/
	static void yield();


	/*
		When a thread is in a deferred cancelstate, it will only stop when
		a cancellation point is reached (eg. blocking io, ...). This function
		forces such a cancellation point, this function could stop the
		calling thread when a cancelrequest was submitted.
	*/
	static void testCancel();


	/*
		This function sets the cancelstate of the calling thread. Two values
		are possible: CancelEnable and CancelDisable. CancelEnable will make
		cancellation of the calling thread possible, CancelDisable makes
		external cancellation not impossible. See also setCancelTypeCurrent.
	*/
	static void setCancelStateCurrent( QThreadConst::CancelState );


	/*
		This function sets the canceltype of the calling thread. Two values
		are possible: CancelAsynchronous and CancelDeferred. CancelAsynchronous
		will stop the thread immediately when a cancellation is requested, this
		no matterwhat the thread is doing at the moment, CancelDeferred will defer
		defer the cancellation until a cancellationpoint is reached (eg. blocking
        io, QThreadUtil::testCancel(), ...). This function automatically
        enables cancellation for the calling thread.
	*/
   	static void setCancelTypeCurrent(QThreadConst::CancelType ); 	


	/*
		This functions returns the QThread object representing the current thread.
		In future versions the result could be changed to a handle (proxy) instead
		of the QThread object self.
	*/
	static QThread *currentThread();
};


class QThreadProc
{
public:

	/*
		This method will be called in the thread. Whenever this method returns, the
		thread will stop.
	*/
	virtual main() = 0;
};


class QThread : public QObject
{

	Q_OBJECT

public:
	QThread ( QThreadProc *threadProc );
	~QThread ();

	/*
		This function will spawn this thread. The main method in
		the QThreadProc object will be called. The started signal
		will be emitted. The function will return immedidately
		although it is implementation and platform dependant if the
		thread already started or not. It could be possible the thread
		already started and terminated when this function returns.
	*/
	void create ();


	/*
		Cancel this thread. If cancellation is enabled and in asynchronous mode
		the thread will stop immediately, if in deferred mode, cancellation will
		only occur in cancellation points, if cancellation was disabled, nothing
		will happen.
	*/
	void cancel ();


	/*
		Calling this function ones will recycle systemresources (stack, ...)
		immediately when this thread terminates, this will also recycle return
		values before one can read them. Calling this function more than once is
		implementation and platform dependant.
	*/
	void detach ();


	/*
		This function will join the calling thread with this thread. The calling
		thread will only resume when this thread terminates (cancels). If this
        thread already terminated, the function will immediately return. If
		more than one thread joins this thread the behavior is implementation and
		platform dependant.
	*/
 	void join ();

	
	/*
		This function returns true if both thread objects (this and thread)
		point to the same thread
	*/
	bool operator == (const QThread &thread);

signals:

	/*
		This signal is emitted whenever the thread starts. The signal will only be
		emitted once. It will be emitted on the just started thread.
	*/
 	started();


	/*
		This signal is emitted when the thread has stopped. It will be emitted only
		once. It will be emitted on the thread just before it is stopped. Except
		for some erroneous circumstances, this signal will always be emitted.
	*/
 	stopped();
};

[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic