Click here to Skip to main content
12,299,451 members (56,332 online)
Click here to Skip to main content

Stats

26.1K views
457 downloads
13 bookmarked
Posted

Cross Platform Threads

, 15 Oct 2006 CPOL
A cross platform thread class.
/*******************************************************************************
** FILE:			XPThreads.h

** DESCRIPTION: 	C++ wrapper on threads
					X-Platform Threads Class. Tested on Mac and Windows, should 
					with other flavors of unix..

** AUTHOR:			Amit Gupta

** CREATED:			07-OCT-2006
********************************************************************************/
#ifndef _XPThreads_H_
#define _XPThreads_H_


#if _WINDOWS
	#include <windows.h>

	typedef unsigned long (*ThreadProc)( void* param );
	typedef DWORD XPThreadId;

#elif __MACH__
	#include "pthread.h"

	typedef pthread_t XPThreadId;
	typedef void* (*ThreadProc)( void* param );

#endif

/*********************************************************************************
** CLASS:			XPThreads

** DESCRIPTION:		
**********************************************************************************/
class XPThreads
{
	private:
		
		XPThreadId		m_Threadid;
		ThreadProc		m_Callback;

#if _WINDOWS
		long			m_nTimeout;
		HANDLE			m_ptrThread;
#endif
	
/******************************************************************************
** FUNCTION:	Stop
*******************************************************************************/
			void Stop();			

	public:

/******************************************************************************
** FUNCTION:	Constructor & Destructor
*******************************************************************************/
			XPThreads(ThreadProc ptrCallback = NULL, long nTimeout = 3000);
			virtual ~XPThreads() throw();

/******************************************************************************
** FUNCTION:	SetThreadProc
*******************************************************************************/
			void SetThreadProc(ThreadProc ptrCallback); 

/******************************************************************************
** FUNCTION:	GetThreadId
*******************************************************************************/
			XPThreadId GetThreadId() 
			{ 
				return m_Threadid; 
			}

/******************************************************************************
** FUNCTION:	Run
*******************************************************************************/
			bool Run();

/******************************************************************************
** FUNCTION:	IsThreadCreated
*******************************************************************************/
			bool IsThreadCreated();
};



#endif

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Share

About the Author

Amit Gupta MDS
Product Manager MetaDesign Solutions
India India
Senior Software Developer with special skills in Developing Applications for Macintosh and Windows.

You may also be interested in...

| Advertise | Privacy | Terms of Use | Mobile
Web02 | 2.8.160525.2 | Last Updated 16 Oct 2006
Article Copyright 2006 by Amit Gupta MDS
Everything else Copyright © CodeProject, 1999-2016
Layout: fixed | fluid