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 /////////////////////////////////////////////////////////////////////////////
12 // ============================================================================
14 // ============================================================================
16 // ----------------------------------------------------------------------------
18 // ----------------------------------------------------------------------------
22 #include <wx/string.h>
26 // ----------------------------------------------------------------------------
27 // conditional compilation
28 // ----------------------------------------------------------------------------
34 // ============================================================================
36 // ============================================================================
38 // ----------------------------------------------------------------------------
40 // ----------------------------------------------------------------------------
44 #include <wx/thread.h>
46 static size_t gs_counter
= (size_t)-1;
47 static wxCriticalSection gs_critsect
;
49 class MyThread
: public wxThread
54 // thread execution starts here
55 virtual void *Entry();
58 virtual void OnExit();
64 MyThread::MyThread(char ch
)
71 void *MyThread::Entry()
74 wxCriticalSectionLocker
lock(gs_critsect
);
75 if ( gs_counter
== (size_t)-1 )
81 for ( size_t n
= 0; n
< 10; n
++ )
95 void MyThread::OnExit()
97 wxCriticalSectionLocker
lock(gs_critsect
);
101 #endif // TEST_THREADS
103 // ----------------------------------------------------------------------------
105 // ----------------------------------------------------------------------------
109 void PrintArray(const char* name
, const wxArrayString
& array
)
111 printf("Dump of the array '%s'\n", name
);
113 size_t nCount
= array
.GetCount();
114 for ( size_t n
= 0; n
< nCount
; n
++ )
116 printf("\t%s[%u] = '%s'\n", name
, n
, array
[n
].c_str());
120 #endif // TEST_ARRAYS
122 // ----------------------------------------------------------------------------
124 // ----------------------------------------------------------------------------
126 int main(int argc
, char **argv
)
128 if ( !wxInitialize() )
130 fprintf(stderr
, "Failed to initialize the wxWindows library, aborting.");
142 puts("*** Initially:");
144 PrintArray("a1", a1
);
146 wxArrayString
a2(a1
);
147 PrintArray("a2", a2
);
149 wxSortedArrayString
a3(a1
);
150 PrintArray("a3", a3
);
152 puts("*** After deleting a string from a1");
155 PrintArray("a1", a1
);
156 PrintArray("a2", a2
);
157 PrintArray("a3", a3
);
159 puts("*** After reassigning a1 to a2 and a3");
161 PrintArray("a2", a2
);
162 PrintArray("a3", a3
);
163 #endif // TEST_ARRAYS
166 static const size_t nThreads
= 3;
167 MyThread
*threads
[nThreads
];
169 for ( n
= 0; n
< nThreads
; n
++ )
171 threads
[n
] = new MyThread('+' + n
);
175 // wait until all threads terminate
178 wxCriticalSectionLocker
lock(gs_critsect
);
183 puts("\nThat's all, folks!");
185 for ( n
= 0; n
< nThreads
; n
++ )
187 threads
[n
]->Delete();
189 #endif // TEST_THREADS