1. wxThread changes (detached/joinable) for MSW and docs updates

2. wxUSE_GUI=0 compilation for MSW (use vc6dll.t with tmake) and many small
   fixes related to this
3. an attempt to make wxLog more MT friendly
4. a small fix for wxRegConfig: it doesn't create empty unused keys any
   more (SetPath() would always create a key, now it's deleted if it was
   empty)


git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@4712 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Vadim Zeitlin
1999-11-27 22:57:06 +00:00
parent aa9a4ae1a5
commit b568d04ffa
24 changed files with 1430 additions and 908 deletions

View File

@@ -30,8 +30,8 @@
// what to test?
//#define TEST_ARRAYS
#define TEST_LOG
//#define TEST_THREADS
//#define TEST_LOG
#define TEST_THREADS
// ============================================================================
// implementation
@@ -47,30 +47,51 @@
static size_t gs_counter = (size_t)-1;
static wxCriticalSection gs_critsect;
static wxCondition gs_cond;
class MyThread : public wxThread
class MyJoinableThread : public wxThread
{
public:
MyThread(char ch);
MyJoinableThread(size_t n) : wxThread(wxTHREAD_JOINABLE)
{ m_n = n; Create(); }
// thread execution starts here
virtual void *Entry();
virtual ExitCode Entry();
private:
size_t m_n;
};
wxThread::ExitCode MyJoinableThread::Entry()
{
unsigned long res = 1;
for ( size_t n = 1; n < m_n; n++ )
{
res *= n;
// it's a loooong calculation :-)
Sleep(100);
}
return (ExitCode)res;
}
class MyDetachedThread : public wxThread
{
public:
MyDetachedThread(char ch) { m_ch = ch; Create(); }
// thread execution starts here
virtual ExitCode Entry();
// and stops here
virtual void OnExit();
public:
private:
char m_ch;
};
MyThread::MyThread(char ch)
{
m_ch = ch;
Create();
}
void *MyThread::Entry()
wxThread::ExitCode MyDetachedThread::Entry()
{
{
wxCriticalSectionLocker lock(gs_critsect);
@@ -80,7 +101,8 @@ void *MyThread::Entry()
gs_counter++;
}
for ( size_t n = 0; n < 10; n++ )
static const size_t nIter = 10;
for ( size_t n = 0; n < nIter; n++ )
{
if ( TestDestroy() )
break;
@@ -91,13 +113,14 @@ void *MyThread::Entry()
wxThread::Sleep(100);
}
return NULL;
return 0;
}
void MyThread::OnExit()
void MyDetachedThread::OnExit()
{
wxCriticalSectionLocker lock(gs_critsect);
gs_counter--;
if ( !--gs_counter )
gs_cond.Signal();
}
#endif // TEST_THREADS
@@ -178,33 +201,44 @@ int main(int argc, char **argv)
printf(msg);
// but this one will because log functions use fixed size buffer
wxLogMessage("A very very long message 2: '%s', the end!\n", s.c_str());
// (note that it doesn't need '\n' at the end neither - will be added
// by wxLog anyhow)
wxLogMessage("A very very long message 2: '%s', the end!", s.c_str());
#endif // TEST_LOG
#ifdef TEST_THREADS
puts("Testing detached threads...");
static const size_t nThreads = 3;
MyThread *threads[nThreads];
MyDetachedThread *threads[nThreads];
size_t n;
for ( n = 0; n < nThreads; n++ )
{
threads[n] = new MyThread('+' + n);
threads[n] = new MyDetachedThread('A' + n);
}
threads[0]->SetPriority(WXTHREAD_MIN_PRIORITY);
threads[1]->SetPriority(WXTHREAD_MAX_PRIORITY);
for ( n = 0; n < nThreads; n++ )
{
threads[n]->Run();
}
// wait until all threads terminate
for ( ;; )
{
wxCriticalSectionLocker lock(gs_critsect);
if ( !gs_counter )
break;
}
wxMutex mutex;
mutex.Lock();
gs_cond.Wait(mutex);
mutex.Unlock();
puts("\nThat's all, folks!");
puts("\n\nTesting a joinable thread used for a loooong calculation...");
for ( n = 0; n < nThreads; n++ )
{
threads[n]->Delete();
}
// calc 10! in the background
MyJoinableThread thread(10);
thread.Run();
printf("\nThread terminated with exit code %lu.\n",
(unsigned long)thread.Wait());
#endif // TEST_THREADS
wxUninitialize();