Click here to Skip to main content
15,891,136 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
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);
}
GeneralContext menu and Dialog names Pin
Rage26-Jan-03 21:21
professionalRage26-Jan-03 21:21 
GeneralRe: Context menu and Dialog names Pin
KaЯl27-Jan-03 0:23
KaЯl27-Jan-03 0:23 
GeneralRe: Context menu and Dialog names Pin
Rage27-Jan-03 0:45
professionalRage27-Jan-03 0:45 
Generale-mail client Pin
Anonymous26-Jan-03 21:02
Anonymous26-Jan-03 21:02 
GeneralRe: e-mail client Pin
benjymous27-Jan-03 0:00
benjymous27-Jan-03 0:00 
GeneralRe: e-mail client Pin
Anonymous27-Jan-03 2:40
Anonymous27-Jan-03 2:40 
GeneralRe: e-mail client Pin
Anonymous28-Jan-03 3:58
Anonymous28-Jan-03 3:58 
GeneralEthernet MAC Address, SNMP method Pin
Rok26-Jan-03 20:53
Rok26-Jan-03 20:53 
GeneralScroll to the end of a MFC RichEditCtrl Pin
p8337026-Jan-03 19:51
p8337026-Jan-03 19:51 
GeneralRe: Scroll to the end of a MFC RichEditCtrl Pin
Joerg Wiedenmann26-Jan-03 21:10
Joerg Wiedenmann26-Jan-03 21:10 
GeneralRe: Scroll to the end of a MFC RichEditCtrl Pin
p8337026-Jan-03 21:14
p8337026-Jan-03 21:14 
GeneralRe: Scroll to the end of a MFC RichEditCtrl Pin
Joerg Wiedenmann27-Jan-03 2:44
Joerg Wiedenmann27-Jan-03 2:44 
GeneralMFC linking issues Pin
Anonymous26-Jan-03 19:37
Anonymous26-Jan-03 19:37 
GeneralRe: MFC linking issues Pin
Chris Losinger26-Jan-03 19:44
professionalChris Losinger26-Jan-03 19:44 
GeneralError in OMF type. Pin
73Zeppelin26-Jan-03 18:42
73Zeppelin26-Jan-03 18:42 
GeneralRe: Error in OMF type. Pin
Chris Losinger26-Jan-03 19:43
professionalChris Losinger26-Jan-03 19:43 
GeneralRe: Error in OMF type. Pin
73Zeppelin27-Jan-03 2:12
73Zeppelin27-Jan-03 2:12 

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.