Skip to content

Instantly share code, notes, and snippets.

@kuenishi
Created May 3, 2009 02:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kuenishi/105799 to your computer and use it in GitHub Desktop.
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
#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