Click here to Skip to main content
15,913,854 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: convert *doc file to *html file Pin
Carlos Antollini27-Jan-03 1:01
Carlos Antollini27-Jan-03 1:01 
GeneralRe: convert *doc file to *html file Pin
ccodes27-Jan-03 2:14
ccodes27-Jan-03 2:14 
GeneralRe: convert *doc file to *html file Pin
Carlos Antollini27-Jan-03 4:13
Carlos Antollini27-Jan-03 4:13 
GeneralRe: convert *doc file to *html file Pin
ccodes27-Jan-03 23:00
ccodes27-Jan-03 23:00 
GeneralDialog and multiple inheritance Pin
Anonymous26-Jan-03 23:46
Anonymous26-Jan-03 23:46 
GeneralRe: Dialog and multiple inheritance Pin
Rage26-Jan-03 23:50
professionalRage26-Jan-03 23:50 
Generaltoolbar programming question Pin
trustno126-Jan-03 23:29
trustno126-Jan-03 23:29 
GeneralRe: toolbar programming question Pin
Rage27-Jan-03 0:37
professionalRage27-Jan-03 0:37 
QuestionInstallation wizard? Pin
*Tom*26-Jan-03 23:23
*Tom*26-Jan-03 23:23 
AnswerRe: Installation wizard? Pin
Rage26-Jan-03 23:51
professionalRage26-Jan-03 23:51 
GeneralRe: Installation wizard? Pin
*Tom*27-Jan-03 0:01
*Tom*27-Jan-03 0:01 
AnswerRe: Installation wizard? Pin
Renjith Ramachandran27-Jan-03 2:42
Renjith Ramachandran27-Jan-03 2:42 
GeneralHandling the user (when takes out a floppy disk while it is working) Pin
Joan M26-Jan-03 22:22
professionalJoan M26-Jan-03 22:22 
GeneralRe: Handling the user (when takes out a floppy disk while it is working) Pin
Rage26-Jan-03 23:54
professionalRage26-Jan-03 23:54 
GeneralRe: Handling the user (when takes out a floppy disk while it is working) Pin
benjymous26-Jan-03 23:57
benjymous26-Jan-03 23:57 
GeneralRe: Handling the user (when takes out a floppy disk while it is working) Pin
*Tom*27-Jan-03 11:26
*Tom*27-Jan-03 11:26 
GeneralRe: Handling the user (when takes out a floppy disk while it is working) Pin
Joan M27-Jan-03 21:22
professionalJoan M27-Jan-03 21:22 
GeneralRe: Handling the user (when takes out a floppy disk while it is working) Pin
*Tom*28-Jan-03 0:12
*Tom*28-Jan-03 0:12 
GeneralInvalid memory access while accessing a dll exported variable Pin
shaunakshaunak26-Jan-03 22:17
shaunakshaunak26-Jan-03 22:17 
GeneralLinker Error Pin
suresh_sathya26-Jan-03 21:53
suresh_sathya26-Jan-03 21:53 
GeneralRe: Linker Error Pin
Daniel Strigl26-Jan-03 22:32
Daniel Strigl26-Jan-03 22:32 
GeneralRe: Linker Error Pin
Mike Nordell27-Jan-03 9:44
Mike Nordell27-Jan-03 9:44 
GeneralMetafile playing(URGENT) Pin
satyavasu26-Jan-03 21:50
satyavasu26-Jan-03 21:50 
GeneralQuestion about thread and TLS Pin
George226-Jan-03 21:40
George226-Jan-03 21:40 
GeneralRe: Question about thread and TLS Pin
George226-Jan-03 21:41
George226-Jan-03 21:41 
Source codes:

class OSThread
{

public:
//
// Call before calling any other OSThread function
static void Initialize();

OSThread();
virtual ~OSThread();

//
// Derived classes must implement their own entry function
virtual void Entry() = 0;
void Start();

static void ThreadYield();
static void Sleep(UInt32 inMsec);

void Join();
void SendStopRequest() { fStopRequested = true; }
Bool16 IsStopRequested() { return fStopRequested; }
void StopAndWaitForThread();

void* GetThreadData() { return fThreadData; }
void SetThreadData(void* inThreadData) { fThreadData = inThreadData; }

// As a convienence to higher levels, each thread has its own date buffer
DateBuffer* GetDateBuffer() { return &fDateBuffer; }

static void* GetMainThreadData() { return sMainThreadData; }
static void SetMainThreadData(void* inData) { sMainThreadData = inData; }

static OSThread* GetCurrent();

private:

static DWORD sThreadStorageIndex;

Bool16 fStopRequested;
Bool16 fJoined;


HANDLE fThreadID;
static unsigned int WINAPI _Entry(LPVOID inThread);
};


void* OSThread::sMainThreadData = NULL;


DWORD OSThread::sThreadStorageIndex = 0;


void OSThread::Initialize()
{
sThreadStorageIndex = ::TlsAlloc();
Assert(sThreadStorageIndex >= 0);
}

OSThread::OSThread()
: fStopRequested(false),
fJoined(false),
fThreadData(NULL)
{
}

OSThread::~OSThread()
{
this->StopAndWaitForThread();
}

void OSThread::Start()
{
unsigned int theId = 0; // We don't care about the identifier
fThreadID = (HANDLE)_beginthreadex( NULL, // Inherit security
0, // Inherit stack size
_Entry, // Entry function
(void*)this, // Entry arg
0, // Begin executing immediately
&theId );
Assert(fThreadID != NULL);

}

void OSThread::StopAndWaitForThread()
{
fStopRequested = true;
if (!fJoined)
Join();
}

void OSThread::Join()
{
// What we're trying to do is allow the thread we want to delete to complete
// running. So we wait for it to stop.
Assert(!fJoined);
fJoined = true;
DWORD theErr = ::WaitForSingleObject(fThreadID, INFINITE);
Assert(theErr == WAIT_OBJECT_0);
}

void OSThread::Sleep(UInt32 inMsec)
{
::Sleep(inMsec);
}

unsigned int WINAPI OSThread::_Entry(LPVOID inThread)
{
OSThread* theThread = (OSThread*)inThread;
bool theErr = ::TlsSetValue(sThreadStorageIndex, theThread);
Assert(theErr == TRUE);
// Run the thread
theThread->Entry();
return NULL;
}

OSThread* OSThread::GetCurrent()
{
return (OSThread *)::TlsGetValue(sThreadStorageIndex);
}

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.