fixed: auto_ptr -> unique_ptr
[opensg.git] / Source / Base / FieldContainer / Node / testNodeThread.cpp
blob31e6d8525b6f3a8a6cb727874489cd29fab95e62
2 #include "OSGBaseInitFunctions.h"
3 #include "OSGNode.h"
5 #ifdef OSG_USE_PTHREADS
6 #include <pthread.h>
8 pthread_t oThread;
10 void *runThread(void *)
12 fprintf(stderr, "run thread \n");
14 fprintf(stderr, "th : %p %p %d 0x%016" PRIx64 " 0x%016" PRIx64 "\n",
15 static_cast<void *>(OSG::Thread::getCurrentChangeList ()),
16 static_cast<void *>(OSG::Thread::getCurrent ()),
17 OSG::Thread::getCurrentAspect (),
18 OSG::Thread::getCurrentNamespaceMask(),
19 OSG::Thread::getCurrentLocalFlags ());
21 fprintf(stderr, "th : %p %p %d 0x%016" PRIx64 " 0x%016" PRIx64 "\n",
22 static_cast<void *>(OSG::Thread::getCurrentChangeList ()),
23 static_cast<void *>(OSG::Thread::getCurrent ()),
24 OSG::Thread::getCurrentAspect (),
25 OSG::Thread::getCurrentNamespaceMask(),
26 OSG::Thread::getCurrentLocalFlags ());
28 OSG::NodeUnrecPtr pNode1 = OSG::Node::create();
30 OSG::NodeUnrecPtr pNode2 = OSG::Node::create();
31 OSG::NodeUnrecPtr pNode3 = OSG::Node::create();
33 pNode1->addChild(pNode2);
34 pNode1->addChild(pNode3);
36 fprintf(stderr, "exit thread\n");
38 return NULL;
41 void runThread1(void *)
43 fprintf(stderr, "run thread \n");
45 fprintf(stderr, "th : %p %p %d 0x%016" PRIx64 " 0x%016" PRIx64 "\n",
46 static_cast<void *>(OSG::Thread::getCurrentChangeList ()),
47 static_cast<void *>(OSG::Thread::getCurrent ()),
48 OSG::Thread::getCurrentAspect (),
49 OSG::Thread::getCurrentNamespaceMask(),
50 OSG::Thread::getCurrentLocalFlags ());
52 fprintf(stderr, "th : %p %p %d 0x%016" PRIx64 " 0x%016" PRIx64 "\n",
53 static_cast<void *>(OSG::Thread::getCurrentChangeList ()),
54 static_cast<void *>(OSG::Thread::getCurrent ()),
55 OSG::Thread::getCurrentAspect (),
56 OSG::Thread::getCurrentNamespaceMask(),
57 OSG::Thread::getCurrentLocalFlags ());
59 OSG::NodeUnrecPtr pNode1 = OSG::Node::create();
61 OSG::NodeUnrecPtr pNode2 = OSG::Node::create();
62 OSG::NodeUnrecPtr pNode3 = OSG::Node::create();
64 pNode1->addChild(pNode2);
65 pNode1->addChild(pNode3);
67 fprintf(stderr, "exit thread\n");
70 int main (int argc, char **argv)
72 OSG::osgInit(argc, argv);
74 #ifdef OSG_ENABLE_AUTOINIT_THREADS
75 OSG::Thread::setFallbackAspectId(42);
76 #endif
78 #ifdef OSG_ENABLE_AUTOINIT_THREADS
79 pthread_create(&oThread, NULL, runThread, NULL);
81 pthread_join(oThread, NULL);
82 #endif
84 #if 1
85 OSG::ThreadRefPtr pThread = OSG::Thread::get(NULL, false);
87 pThread->runFunction(runThread1, 0, NULL);
89 OSG::Thread::join(pThread);
91 pThread = NULL;
92 #endif
93 OSG::osgExit();
95 return 0;
98 #endif
100 #ifdef OSG_USE_WINTHREADS
102 OSG::Handle oThread;
104 void *runThread(void *)
106 fprintf(stderr, "run thread \n");
108 #if 1
109 fprintf(stderr, "%d ",
110 OSG::Thread::getCurrentAspect ());
112 fprintf(stderr, "th : T:%p ",
113 static_cast<void *>(OSG::Thread::getCurrent ()));
114 fprintf(stderr, "CL:%p ",
115 static_cast<void *>(OSG::Thread::getCurrentChangeList ()));
117 fprintf(stderr, "0x%016" PRIx64 " ",
118 OSG::Thread::getCurrentNamespaceMask());
120 fprintf(stderr, "0x%016" PRIx64 "\n",
121 OSG::Thread::getCurrentLocalFlags ());
123 OSG::NodeUnrecPtr pNode1 = OSG::Node::create();
125 OSG::NodeUnrecPtr pNode2 = OSG::Node::create();
126 OSG::NodeUnrecPtr pNode3 = OSG::Node::create();
128 pNode1->addChild(pNode2);
129 pNode1->addChild(pNode3);
130 #endif
132 fprintf(stderr, "exit thread\n");
134 return NULL;
137 void runThread1(void *)
139 fprintf(stderr, "run thread \n");
141 fprintf(stderr, "th : CL:%p T:%p %d 0x%016" PRIx64 " 0x%016" PRIx64 "\n",
142 static_cast<void *>(OSG::Thread::getCurrentChangeList ()),
143 static_cast<void *>(OSG::Thread::getCurrent ()),
144 OSG::Thread::getCurrentAspect (),
145 OSG::Thread::getCurrentNamespaceMask(),
146 OSG::Thread::getCurrentLocalFlags ());
148 fprintf(stderr, "th : CL:%p T:%p %d 0x%016" PRIx64 " 0x%016" PRIx64 "\n",
149 static_cast<void *>(OSG::Thread::getCurrentChangeList ()),
150 static_cast<void *>(OSG::Thread::getCurrent ()),
151 OSG::Thread::getCurrentAspect (),
152 OSG::Thread::getCurrentNamespaceMask(),
153 OSG::Thread::getCurrentLocalFlags ());
155 OSG::NodeUnrecPtr pNode1 = OSG::Node::create();
157 OSG::NodeUnrecPtr pNode2 = OSG::Node::create();
158 OSG::NodeUnrecPtr pNode3 = OSG::Node::create();
160 pNode1->addChild(pNode2);
161 pNode1->addChild(pNode3);
163 fprintf(stderr, "exit thread\n");
166 int main (int argc, char **argv)
168 OSG::osgInit(argc, argv);
170 #ifdef OSG_ENABLE_AUTOINIT_THREADS
171 OSG::Thread::setFallbackAspectId(42);
172 #endif
174 #ifdef OSG_ENABLE_AUTOINIT_THREADS
175 OSG::DWord tmp;
177 OSG::Handle rc = CreateThread(NULL,
179 (LPTHREAD_START_ROUTINE) runThread,
182 &tmp);
184 WaitForSingleObject(rc, INFINITE);
185 #endif
187 #if 1
188 OSG::ThreadRefPtr pThread = OSG::Thread::get(NULL, false);
190 pThread->runFunction(runThread1, 0, NULL);
192 OSG::Thread::join(pThread);
194 pThread = NULL;
195 #endif
196 OSG::osgExit();
198 return 0;
201 #endif