|
Boost : |
From: Alexander Terekhov (terekhov_at_[hidden])
Date: 2002-08-06 14:37:46
Peter Dimov wrote:
[...]
> To put things in perspective:
>
> int foo()
> {
> return 10;
> }
>
> std::cout << boost::thread(foo).join() << std::endl;
Nah, < using namespace whatever >
int my_operation( int );
class my_fancy_thread : public thread {
public:
class attr : public thread::attr {
public: /*...add some fancy stuff...*/ };
/*...add some fancy stuff...*/ };
// called by thread::attr::new_thread<> function(s)
thread* create_thread_object( const my_fancy_thread::attr& );
// overloads NOOP defaults; called in the context of NEW thread
void on_thread_start( my_fancy_thread* );
void on_thread_termination( my_fancy_thread* );
void thread::main()
{
joinable_thread_ptr< int,my_fancy_thread > pthread =
my_fancy_thread::attr().set_system_contention_scope()
.set_sched_policy( sched::FIFO )
.set_fancy_blabla()
.set_initialy_suspended( true )
.set_daemon( true )
.new_thread( my_operation,
some_magic_number );
/*...*/
pthread->start();
// result is stored in joinable_thread_object< result,thread_type >
// managed by smart thread ptr (thread_ptr<>/joinable_thread_ptr<>)
int* presult = pthread->timedjoin( timeout::relative( 1000 ) );
if ( thread::timedout( presult ) &&
thread::canceled( presult = pthread->cancel().join() ) ) {
cout << "OOPS: timedout and canceled!";
}
else {
cout << "DONE: " << *presult;
}
return 0;
}
> Less readable? OK, let's attribute this to taste.
Indeed. ;-)
BTW,
"William E. Kempf" wrote:
[...]
> Exceptions are, by design, meant to either be caught or to propogate up the
> calling stack, ....
Really?
< ISO/IEC 14882:1998(E) >
"If no matching handler is found in a program, the function
terminate() is called; whether or not the stack is unwound
before this call to terminate() is implementation-defined
(15.5.1)."
< C++ Standard Core Language Active Issues, Revision 22 >
"Bjarne Stroustrup: I strongly prefer to have the call to
std::terminate() be conforming. I see std::terminate() as
a proper way to blow away "the current mess" and get to the
next level of error handling. I do not want that escape to
be non-conforming that would imply that programs relying
on a error handling based on serious errors being handled
by terminating a process (which happens to be a C++ program)
in std::terminate() becomes non-conforming. In many systems,
there are and/or should be error-handling and recovery
mechanisms beyond what is offered by a single C++ program."
regards,
alexander.
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk