1. wxLog::FlushActive() added

2. threads can be used in console mode


git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@3877 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Vadim Zeitlin
1999-10-07 18:12:57 +00:00
parent 48115f4a69
commit bbfa03228a
4 changed files with 141 additions and 12 deletions

View File

@@ -12,18 +12,95 @@
#include <stdio.h>
#include <wx/string.h>
#include <wx/file.h>
#include <wx/app.h>
#include <wx/thread.h>
int main()
static size_t gs_counter = (size_t)-1;
static wxCriticalSection gs_critsect;
class MyThread : public wxThread
{
public:
MyThread(char ch);
// thread execution starts here
virtual void *Entry();
// and stops here
virtual void OnExit();
public:
char m_ch;
};
MyThread::MyThread(char ch)
{
m_ch = ch;
Create();
}
void *MyThread::Entry()
{
{
wxCriticalSectionLocker lock(gs_critsect);
if ( gs_counter == (size_t)-1 )
gs_counter = 1;
else
gs_counter++;
}
for ( size_t n = 0; n < 10; n++ )
{
if ( TestDestroy() )
break;
putchar(m_ch);
fflush(stdout);
wxThread::Sleep(100);
}
return NULL;
}
void MyThread::OnExit()
{
wxCriticalSectionLocker lock(gs_critsect);
gs_counter--;
}
int main(int argc, char **argv)
{
if ( !wxInitialize() )
{
fprintf(stderr, "Failed to initialize the wxWindows library, aborting.");
}
wxString s("Hello, ");
static const size_t nThreads = 3;
MyThread *threads[nThreads];
size_t n;
for ( n = 0; n < nThreads; n++ )
{
threads[n] = new MyThread('+' + n);
threads[n]->Run();
}
wxLogMessage(s + "world!");
// wait until all threads terminate
for ( ;; )
{
wxCriticalSectionLocker lock(gs_critsect);
if ( !gs_counter )
break;
}
puts("\nThat's all, folks!");
for ( n = 0; n < nThreads; n++ )
{
threads[n]->Delete();
}
wxUninitialize();