| 
									
										
										
										
											2018-02-19 02:02:31 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | // lw_thread_test.cpp
 | 
					
						
							|  |  |  | //
 | 
					
						
							|  |  |  | // Copyright 2018 Peter Dimov
 | 
					
						
							|  |  |  | // Distributed under the Boost Software License, Version 1.0.
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-09-26 04:11:10 +03:00
										 |  |  | #include <boost/smart_ptr/detail/lightweight_thread.hpp>
 | 
					
						
							| 
									
										
										
										
											2018-02-19 02:02:31 +02:00
										 |  |  | #include <boost/smart_ptr/detail/atomic_count.hpp>
 | 
					
						
							| 
									
										
										
										
											2024-09-26 04:11:10 +03:00
										 |  |  | #include <boost/core/lightweight_test.hpp>
 | 
					
						
							| 
									
										
										
										
											2018-02-19 02:02:31 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | boost::detail::atomic_count count( 0 ); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void f() | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     ++count; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | int main() | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     int const N = 4; | 
					
						
							| 
									
										
										
										
											2018-03-08 01:19:44 +02:00
										 |  |  |     boost::detail::lw_thread_t th[ N ] = {}; | 
					
						
							| 
									
										
										
										
											2018-02-19 02:02:31 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |     for( int i = 0; i < N; ++i ) | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         boost::detail::lw_thread_create( th[ i ], f ); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     for( int i = 0; i < N; ++i ) | 
					
						
							|  |  |  |     { | 
					
						
							| 
									
										
										
										
											2018-03-08 01:19:44 +02:00
										 |  |  |         boost::detail::lw_thread_join( th[ i ] ); | 
					
						
							| 
									
										
										
										
											2018-02-19 02:02:31 +02:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     BOOST_TEST_EQ( count, N ); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     return boost::report_errors(); | 
					
						
							|  |  |  | } |