Created
May 3, 2009 02:24
-
-
Save kuenishi/105799 to your computer and use it in GitHub Desktop.
test code for do-not-use-stack-space too much in normal function
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <pthread.h> | |
#include <iostream> | |
#include <string> | |
// > $ g++ -g template_thread_test.cpp -lpthread | |
// > $ ./a.out | |
using namespace std; | |
template <typename Type1, typename Type2> | |
class Hoge{ | |
public: | |
Type1 t_; | |
Type2 s_; | |
Hoge(){}; | |
}; | |
template < template <typename, typename> class Type > | |
void * test_thread(void * p){ | |
char tmp[1024*1024]; //ここでセグフォる | |
Type<int,int> *tp = reinterpret_cast<Type<int,int> *>(p); | |
cout << __func__ << endl; | |
cout << typeid(*tp).name() << endl; | |
}; | |
template < template <typename,typename> class Type> | |
void spawn_and_join(const int& t){ | |
Type<int,int> * p = new Type<int,int>; | |
p->t_ = t; | |
pthread_t pid; | |
pthread_create(&pid, NULL, test_thread<Type>, (void*)p ); | |
pthread_join(pid, NULL); | |
}; | |
int main(){ | |
spawn_and_join<Hoge>(4); | |
// spawn_and_join<Hoge>("hogehoge"); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment