]>
git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/thread/tutorial/factorial.cpp
1 // Copyright (C) 2001-2003
4 // Distributed under the Boost Software License, Version 1.0. (See accompanying
5 // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
7 #include <boost/thread/thread.hpp>
13 factorial(int x
, int& res
) : x(x
), res(res
) { }
14 void operator()() { res
= calculate(x
); }
15 int result() const { return res
; }
18 int calculate(int x
) { return x
<= 1 ? 1 : x
* calculate(x
-1); }
28 factorial
f(10, result
);
29 boost::thread
thrd(f
);
31 std::cout
<< "10! = " << result
<< std::endl
;