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

sample/simple_proc/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> threads_1::mutex_sem_t g_sem; threads_1::cond_var_t g_finished( g_sem ); void thread_proc( void * ) { std::cout << "Started\n" << std::flush; std::cout << "Finished\n" << std::flush; threads_1::mutex_sem_t::lock_t lock( g_sem ); g_finished.notify_one(); } int main() { threads_1::mutex_sem_t::lock_t lock( g_sem ); std::cout << "Start child thread\n" << std::flush; threads_1::begin_thread( thread_proc, 0 ); g_finished.wait(); std::cout << "Child thread finished\n" << std::flush; 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 threads_1::mutex_sem_t g_sem; 00032 threads_1::cond_var_t g_finished( g_sem ); 00033 00034 void 00035 thread_proc( void * ) 00036 { 00037 std::cout << "Started\n" << std::flush; 00038 std::cout << "Finished\n" << std::flush; 00039 00040 threads_1::mutex_sem_t::lock_t lock( g_sem ); 00041 g_finished.notify_one(); 00042 } 00043 00044 int 00045 main() 00046 { 00047 threads_1::mutex_sem_t::lock_t lock( g_sem ); 00048 00049 std::cout << "Start child thread\n" << std::flush; 00050 00051 threads_1::begin_thread( thread_proc, 0 ); 00052 00053 g_finished.wait(); 00054 00055 std::cout << "Child thread finished\n" << std::flush; 00056 00057 return 0; 00058 } 00059

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