#include <pthread.h>
#include <iostream>
using namespace std;
void OnCreateThread()
{
cout << "Create a thread." << endl;
}
void OnExitThread()
{
cout << "Exit a thread." << endl;
}
void f(void*) {}
int main()
{
//
// What to do here ???
//
pthread_t dummy;
pthread_create(&dummy, 0, f, 0);
pthread_create(&dummy, 0, f, 0);
while (true);
}
コードは2つのネイティブスレッド、std::thread
以外を作成し、次のように私は、出力にそれをしたい:スレッドの作成と終了時に関数を呼び出す方法は?
Create a thread. Create a thread. Exit a thread. Exit a thread.
をそれはFlsXXX機能を使用して、Windowsの下で行うことができます。
しかし、Linuxでも実行できるかどうかわかりません。
Linuxでは標準的な方法がありますか?
あなたは 'pthread_create'の使い方を知りたいのですか、あるいは望みの出力を得る方法を知りたいですか? – Chad
あなたの[pthreads(7)のマニュアルページ](http://manpages.courier-mta.org//htmlman7/pthreads.7.html)にすべてのスレッド関数が書かれています。そこに文書化されていなければ、それは存在しません。ここでの答えは、文字通り、RTFMです。 –
これらの関数を登録できない場合でも、pthread_createをシャドウできます。冗談だよ... – felix