「boost::thread」の版間の差分

提供: C++入門
移動: 案内検索
行10: 行10:
  
 
== 概要 ==
 
== 概要 ==
 +
 +
[[boost thread]] のサンプルです。
  
 
== サンプル ==
 
== サンプル ==
行15: 行17:
 
* [[boost thread 1つのスレッドだけ動かすシンプルな例]]
 
* [[boost thread 1つのスレッドだけ動かすシンプルな例]]
 
* [[boost thread 2つのスレッドを動かすシンプルな例]]
 
* [[boost thread 2つのスレッドを動かすシンプルな例]]
 
== インストール ==
 
 
<syntaxhighlight lang="bash">
 
 
</syntaxhighlight>
 
  
 
== ヘッダファイル ==
 
== ヘッダファイル ==
行62: 行58:
 
</syntaxhighlight>
 
</syntaxhighlight>
  
== boost_thread_1.cpp の例==
+
=== コンパイル ===
  
=== ソースコード boost_thread_1.cpp ===
+
コンパイルには、 boost_thread をリンクする必要があります。
 
+
<syntaxhighlight lang="cpp">
+
#include <boost/thread.hpp>
+
#include <iostream>
+
 
+
void
+
thread_1 () {
+
        std::cout << __PRETTY_FUNCTION__ << std::endl;
+
}
+
 
+
int
+
main(int argc, char const* argv[])
+
{
+
        boost::thread th1(thread_1);
+
 
+
        th1.join ();
+
 
+
        return 0;
+
}
+
 
+
</syntaxhighlight>
+
 
+
=== コンパイル ===
+
  
 
<syntaxhighlight lang="bash">
 
<syntaxhighlight lang="bash">
 
g++ -I/usr/local/include -L/usr/local/lib -Lboost_thread boost_thread_1.cpp -o boost_thread_1
 
g++ -I/usr/local/include -L/usr/local/lib -Lboost_thread boost_thread_1.cpp -o boost_thread_1
 
</syntaxhighlight>
 
</syntaxhighlight>
 
=== 実行例 ===
 
 
<syntaxhighlight lang="bash">
 
% ./boost_thread_1
 
void thread_1()
 
 
</syntaxhighlight>
 
 
 
  
 
== 関連項目 ==
 
== 関連項目 ==

2013年3月10日 (日) 12:42時点における版


読み方

boost thread
ぶーすと すれっど

概要

boost thread のサンプルです。

サンプル

ヘッダファイル

#include <boost/thread.hpp>
#include <boost/thread/thread.hpp>
 
namespace boost
{
  class thread;
  void swap(thread& lhs,thread& rhs) noexcept;
 
  namespace this_thread
  {
    thread::id get_id() noexcept;
    template<typename TimeDuration>
    void yield() noexcept; // DEPRECATED
    template <class Clock, class Duration>
    void sleep_until(const chrono::time_point<Clock, Duration>& abs_time);
    template <class Rep, class Period>
    void sleep_for(const chrono::duration<Rep, Period>& rel_time);
 
    template<typename Callable>
    void at_thread_exit(Callable func); // EXTENSION
 
    void interruption_point(); // EXTENSION
    bool interruption_requested() noexcept; // EXTENSION
    bool interruption_enabled() noexcept; // EXTENSION 
    class disable_interruption; // EXTENSION
    class restore_interruption; // EXTENSION
 
  #if defined BOOST_THREAD_USES_DATETIME
    template <TimeDuration>
    void sleep(TimeDuration const& rel_time);  // DEPRECATED
    void sleep(system_time const& abs_time); // DEPRECATED
  #endif
  }
  class thread_group; // EXTENSION

コンパイル

コンパイルには、 boost_thread をリンクする必要があります。

g++ -I/usr/local/include -L/usr/local/lib -Lboost_thread boost_thread_1.cpp -o boost_thread_1

関連項目