1 /////////////////////////////////////////////////////////////////////////////
2 // Name: samples/console/console.cpp
3 // Purpose: a sample console (as opposed to GUI) progam using wxWindows
4 // Author: Vadim Zeitlin
8 // Copyright: (c) 1999 Vadim Zeitlin <zeitlin@dptmaths.ens-cachan.fr>
9 // Licence: wxWindows license
10 /////////////////////////////////////////////////////////////////////////////
14 #include <wx/string.h>
17 #include <wx/thread.h>
19 static size_t gs_counter
= (size_t)-1;
20 static wxCriticalSection gs_critsect
;
22 class MyThread
: public wxThread
27 // thread execution starts here
28 virtual void *Entry();
31 virtual void OnExit();
37 MyThread::MyThread(char ch
)
44 void *MyThread::Entry()
47 wxCriticalSectionLocker
lock(gs_critsect
);
48 if ( gs_counter
== (size_t)-1 )
54 for ( size_t n
= 0; n
< 10; n
++ )
68 void MyThread::OnExit()
70 wxCriticalSectionLocker
lock(gs_critsect
);
74 int main(int argc
, char **argv
)
76 if ( !wxInitialize() )
78 fprintf(stderr
, "Failed to initialize the wxWindows library, aborting.");
81 static const size_t nThreads
= 3;
82 MyThread
*threads
[nThreads
];
84 for ( n
= 0; n
< nThreads
; n
++ )
86 threads
[n
] = new MyThread('+' + n
);
90 // wait until all threads terminate
93 wxCriticalSectionLocker
lock(gs_critsect
);
98 puts("\nThat's all, folks!");
100 for ( n
= 0; n
< nThreads
; n
++ )
102 threads
[n
]->Delete();