Титульная страница | Пространства имен | Алфавитный указатель | Классы | Файлы | Члены пространства имен | Члены классов | Описания | Примеры

sample/simple/main.cpp

/* threads_1: Multithreading support library Yauheni A. Akhotnikau (C) 2002-2003 eao197@yahoo.com ------------------------------------------------- Permission is granted to anyone to use this software for any purpose on any computer system, and to redistribute it freely, subject to the following restrictions: 1. This software is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 2. The origin of this software must not be misrepresented, either by explicit claim or by omission. 3. Altered versions must be plainly marked as such, and must not be misrepresented as being the original software. ------------------------------------------------- */ #include <iostream> #include <cpp_util_2/h/defs.hpp> #include <threads_1/h/threads.hpp> void show_str( const char * s ) { static threads_1::mutex_sem_t s_sem; threads_1::mutex_sem_t::lock_t lock( s_sem ); std::cout << s << std::endl; } class my_thread_t : public threads_1::thread_t { public : my_thread_t(); virtual ~my_thread_t(); protected : virtual void body(); }; my_thread_t::my_thread_t() { } my_thread_t::~my_thread_t() { } void my_thread_t::body() { const char * lines[] = { "line-1", "line-2", "line-3", "line-4", "line-5", "line-6", "line-7", 0 }; for( const char ** p = lines; *p; ++p ) show_str( *p ); } int main() { my_thread_t threads[ 5 ]; std::cout << "Start" << std::endl; int i; for( i = 0; i != CPP_UTIL_2_ASIZE( threads ); ++i ) threads[ i ].start(); for( i = 0; i != CPP_UTIL_2_ASIZE( threads ); ++i ) threads[ i ].wait(); std::cout << "Finish" << std::endl; return 0; }
00001 /* 00002 00003 threads_1: Multithreading support library 00004 Yauheni A. Akhotnikau (C) 2002-2003 00005 eao197@yahoo.com 00006 ------------------------------------------------- 00007 00008 Permission is granted to anyone to use this software for any purpose on any 00009 computer system, and to redistribute it freely, subject to the following 00010 restrictions: 00011 00012 1. This software is distributed in the hope that it will be useful, 00013 but WITHOUT ANY WARRANTY; without even the implied warranty of 00014 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 00015 00016 2. The origin of this software must not be misrepresented, either by 00017 explicit claim or by omission. 00018 00019 3. Altered versions must be plainly marked as such, and must not be 00020 misrepresented as being the original software. 00021 00022 ------------------------------------------------- 00023 00024 */ 00025 #include <iostream> 00026 00027 #include <cpp_util_2/h/defs.hpp> 00028 00029 #include <threads_1/h/threads.hpp> 00030 00031 void 00032 show_str( const char * s ) 00033 { 00034 static threads_1::mutex_sem_t s_sem; 00035 00036 threads_1::mutex_sem_t::lock_t lock( s_sem ); 00037 std::cout << s << std::endl; 00038 } 00039 00040 class my_thread_t : 00041 public threads_1::thread_t 00042 { 00043 public : 00044 my_thread_t(); 00045 virtual ~my_thread_t(); 00046 00047 protected : 00048 virtual void 00049 body(); 00050 }; 00051 00052 my_thread_t::my_thread_t() 00053 { 00054 } 00055 my_thread_t::~my_thread_t() 00056 { 00057 } 00058 00059 void 00060 my_thread_t::body() 00061 { 00062 const char * lines[] = { "line-1", "line-2", "line-3", 00063 "line-4", "line-5", "line-6", "line-7", 0 }; 00064 00065 for( const char ** p = lines; *p; ++p ) 00066 show_str( *p ); 00067 } 00068 00069 int 00070 main() 00071 { 00072 my_thread_t threads[ 5 ]; 00073 00074 std::cout << "Start" << std::endl; 00075 00076 int i; 00077 for( i = 0; i != CPP_UTIL_2_ASIZE( threads ); ++i ) 00078 threads[ i ].start(); 00079 00080 for( i = 0; i != CPP_UTIL_2_ASIZE( threads ); ++i ) 00081 threads[ i ].wait(); 00082 00083 std::cout << "Finish" << std::endl; 00084 00085 return 0; 00086 } 00087

Документация по threads_1. Последние изменения: Wed Aug 4 06:46:00 2004. Создано системой doxygen 1.3.7
Hosted by uCoz