GTK+ IOStream  Beta
<< GTK+ >> add C++ IOStream operators to GTK+. Now with extra abilities ... like network serialisation
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
ThreadTest.C
Go to the documentation of this file.
1 /* Copyright 2000-2013 Matt Flax <flatmax@flatmax.org>
2  This file is part of GTK+ IOStream class set
3 
4  GTK+ IOStream is free software; you can redistribute it and/or modify
5  it under the terms of the GNU General Public License as published by
6  the Free Software Foundation; either version 2 of the License, or
7  (at your option) any later version.
8 
9  GTK+ IOStream is distributed in the hope that it will be useful,
10  but WITHOUT ANY WARRANTY; without even the implied warranty of
11  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  GNU General Public License for more details.
13 
14  You have received a copy of the GNU General Public License
15  along with GTK+ IOStream
16  */
17 
18 /*
19 Author: Matt Flax <flatmax@flatmax.org>
20 Date: 2013.05.03
21 */
22 
23 #include "Thread.H"
24 #include <unistd.h>
25 
26 #include <iostream>
27 using namespace std;
28 
29 class ThreadedClass : public Thread {
30  int variable;
31 public:
32 #ifdef USE_GLIB_THREADS
33  static void staticMethod(void *data){
34  ThreadedClass *tc=static_cast<ThreadedClass*>(data);
35  tc->method();
36  }
37 #else
38  static void *staticMethod(void *data){
39  ThreadedClass *tc=static_cast<ThreadedClass*>(data);
40  tc->method();
41  cout <<"data"<<data<<endl;
42  tc->exit(data);
43  return data;
44  }
45 #endif
46 
47  void setVariable(int var){
48  variable=var;
49  }
50 
51  void method(void){
52  sleep(1);
53  cout<<"varibale = "<<++variable<<endl;
54  }
55 };
56 
57 int main(int argc, char *argv[]){
58 
59  ThreadedClass threadedClass;
60  threadedClass.setVariable(3);
61  threadedClass.run(threadedClass.staticMethod, static_cast<void*>(&threadedClass));
62  cout<<&threadedClass<<'\t'<<threadedClass.meetThread()<<endl;
63 }