// ------------------------------- // // -------- Start of File -------- // // ------------------------------- // // ----------------------------------------------------------- // // C++ Source Code File Name: testprog.cpp // Compiler Used: MSVC40, egcs-2.90.29, HP CPP 10.24 // Produced By: Doug Gaer // File Creation Date: 03/25/2000 // Date Last Modified: 05/25/2000 // Copyright (c) 2000 Douglas M. Gaer // ----------------------------------------------------------- // // ------------- Program Description and Details ------------- // // ----------------------------------------------------------- // /* The VBD and VBS C++ classes are copyright (c) 1997 and 2000 by Douglas M. Gaer. All those who put this code or its derivatives in a commercial product MUST mention this copyright in their documentation for users of the products in which this code or its derivative classes are used. Otherwise, you have the freedom to redistribute verbatim copies of this source code, adapt it to your specific needs, or improve the code and release your improvements to the public provided that the modified files carry prominent notices stating that you changed the files and the date of any change. THIS SOFTWARE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. THE ENTIRE RISK OF THE QUALITY AND PERFORMANCE OF THIS SOFTWARE IS WITH YOU. SHOULD ANY ELEMENT OF THIS SOFTWARE PROVE DEFECTIVE, YOU WILL ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR, OR CORRECTION. Test program demonstrating how to change the detachstate attribute of a newly created thread. You cannot use the thread ID (the value of type vbThread_t::thread_is) for a detached thread. This means that you cannot cancel the thread or use the vbThread::JoinThread() function to to wait for the thread to complete or to retrieve the thread's exit status. The system will reclaim a detached thread's resources when the detach thread exits. */ // ----------------------------------------------------------- // #include <iostream.h> #include "vbthread.h" class SimpleThread : public vbThread { private: // Base class interface void *ThreadEntryRoutine(vbThread_t *thread); }; void *SimpleThread::ThreadEntryRoutine(vbThread_t *thread) // Thread's entry function { cout << "Executing thread: " << (int)thread->GetThreadParm() << ", " << thread->ThreadTypeMessage() << '\n' << flush; return 0; } int main() { const unsigned NUM_THREADS = 10; vbThreadType type = vbTHREAD_TYPE_DETACHED; SimpleThread *t = new SimpleThread; vbThread_t *thread[NUM_THREADS]; unsigned i; cout << "Creating " << NUM_THREADS << " threads" << endl; for(i = 0; i < NUM_THREADS; i++) { thread[i] = t->CreateThread((void *)i, type); // Check for any errors if(thread[i]->GetThreadError() != vbTHREAD_NO_ERROR) cout << thread[i]->ThreadExceptionMessage() << endl; // Allow the threads to print there messages in order t->sSleep(1); } cout << "Waiting for the all treads to finish..." << endl; t->sSleep(3); cout << endl; cout << "Destroying all the threads..." << endl; for(i = 0; i < NUM_THREADS; i++) t->DestroyThread(thread[i]); cout << "Exiting..." << endl; delete t; return 0; // Exit the process, terminating all threads } // ----------------------------------------------------------- // // ------------------------------- // // --------- End of File --------- // // ------------------------------- //