#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);
}
的代码创建了两个原生线程,比std::thread
其他的,我希望它输出如下:如何调用线程创建和退出的函数?
Create a thread. Create a thread. Exit a thread. Exit a thread.
它可以在Windows下使用FlsXXX函数来完成。
但是,我不知道它是否也可以在Linux下完成。
在Linux下有没有标准的方法?
你想知道如何使用'pthread_create'或者你想知道如何得到你想要的输出吗? – Chad
您将在[pthreads(7)手册页](http://manpages.courier-mta.org//htmlman7/pthreads.7.html)中找到记录的所有线程函数。如果它没有记录在那里,它不存在。从字面上看,这里的答案是RTFM。 –
如果你不能注册这些函数,你仍然可以影响pthread_create。我只是在开玩笑... – felix