Reid Spencer | e8cdc8b | 2005-07-12 21:51:33 +0000 | [diff] [blame] | 1 | //===-- examples/ParallelJIT/ParallelJIT.cpp - Exercise threaded-safe JIT -===// |
| 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
| 5 | // This file was developed by Evan Jones and is distributed under the |
| 6 | // University of Illinois Open Source License. See LICENSE.TXT for details. |
| 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | // |
| 10 | // Parallel JIT |
| 11 | // |
Jeff Cohen | 00b16889 | 2005-07-27 06:12:32 +0000 | [diff] [blame] | 12 | // This test program creates two LLVM functions then calls them from three |
Reid Spencer | e8cdc8b | 2005-07-12 21:51:33 +0000 | [diff] [blame] | 13 | // separate threads. It requires the pthreads library. |
| 14 | // The three threads are created and then block waiting on a condition variable. |
| 15 | // Once all threads are blocked on the conditional variable, the main thread |
| 16 | // wakes them up. This complicated work is performed so that all three threads |
| 17 | // call into the JIT at the same time (or the best possible approximation of the |
| 18 | // same time). This test had assertion errors until I got the locking right. |
| 19 | |
| 20 | #include <pthread.h> |
| 21 | #include "llvm/Module.h" |
| 22 | #include "llvm/Constants.h" |
| 23 | #include "llvm/Type.h" |
| 24 | #include "llvm/Instructions.h" |
| 25 | #include "llvm/ModuleProvider.h" |
Jeff Cohen | afebb44 | 2006-03-24 03:11:31 +0000 | [diff] [blame] | 26 | #include "llvm/ExecutionEngine/JIT.h" |
| 27 | #include "llvm/ExecutionEngine/Interpreter.h" |
Reid Spencer | e8cdc8b | 2005-07-12 21:51:33 +0000 | [diff] [blame] | 28 | #include "llvm/ExecutionEngine/GenericValue.h" |
| 29 | #include <iostream> |
| 30 | using namespace llvm; |
| 31 | |
Chris Lattner | 6a98754 | 2007-01-07 07:40:09 +0000 | [diff] [blame^] | 32 | static Function* createAdd1(Module *M) { |
Reid Spencer | e8cdc8b | 2005-07-12 21:51:33 +0000 | [diff] [blame] | 33 | // Create the add1 function entry and insert this entry into module M. The |
| 34 | // function will have a return type of "int" and take an argument of "int". |
| 35 | // The '0' terminates the list of argument types. |
Chris Lattner | 6a98754 | 2007-01-07 07:40:09 +0000 | [diff] [blame^] | 36 | Function *Add1F = |
| 37 | cast<Function>(M->getOrInsertFunction("add1", Type::Int32Ty, Type::Int32Ty, |
| 38 | (Type *)0)); |
Jeff Cohen | 00b16889 | 2005-07-27 06:12:32 +0000 | [diff] [blame] | 39 | |
Reid Spencer | e8cdc8b | 2005-07-12 21:51:33 +0000 | [diff] [blame] | 40 | // Add a basic block to the function. As before, it automatically inserts |
| 41 | // because of the last argument. |
| 42 | BasicBlock *BB = new BasicBlock("EntryBlock", Add1F); |
Jeff Cohen | 00b16889 | 2005-07-27 06:12:32 +0000 | [diff] [blame] | 43 | |
Reid Spencer | e8cdc8b | 2005-07-12 21:51:33 +0000 | [diff] [blame] | 44 | // Get pointers to the constant `1'. |
Reid Spencer | db8d2be | 2006-12-31 05:50:28 +0000 | [diff] [blame] | 45 | Value *One = ConstantInt::get(Type::Int32Ty, 1); |
Jeff Cohen | 00b16889 | 2005-07-27 06:12:32 +0000 | [diff] [blame] | 46 | |
Reid Spencer | e8cdc8b | 2005-07-12 21:51:33 +0000 | [diff] [blame] | 47 | // Get pointers to the integer argument of the add1 function... |
| 48 | assert(Add1F->arg_begin() != Add1F->arg_end()); // Make sure there's an arg |
| 49 | Argument *ArgX = Add1F->arg_begin(); // Get the arg |
| 50 | ArgX->setName("AnArg"); // Give it a nice symbolic name for fun. |
Jeff Cohen | 00b16889 | 2005-07-27 06:12:32 +0000 | [diff] [blame] | 51 | |
Reid Spencer | e8cdc8b | 2005-07-12 21:51:33 +0000 | [diff] [blame] | 52 | // Create the add instruction, inserting it into the end of BB. |
| 53 | Instruction *Add = BinaryOperator::createAdd(One, ArgX, "addresult", BB); |
Jeff Cohen | 00b16889 | 2005-07-27 06:12:32 +0000 | [diff] [blame] | 54 | |
Reid Spencer | e8cdc8b | 2005-07-12 21:51:33 +0000 | [diff] [blame] | 55 | // Create the return instruction and add it to the basic block |
| 56 | new ReturnInst(Add, BB); |
Jeff Cohen | 00b16889 | 2005-07-27 06:12:32 +0000 | [diff] [blame] | 57 | |
| 58 | // Now, function add1 is ready. |
Reid Spencer | e8cdc8b | 2005-07-12 21:51:33 +0000 | [diff] [blame] | 59 | return Add1F; |
| 60 | } |
| 61 | |
Chris Lattner | 6a98754 | 2007-01-07 07:40:09 +0000 | [diff] [blame^] | 62 | static Function *CreateFibFunction(Module *M) { |
Reid Spencer | e8cdc8b | 2005-07-12 21:51:33 +0000 | [diff] [blame] | 63 | // Create the fib function and insert it into module M. This function is said |
| 64 | // to return an int and take an int parameter. |
Chris Lattner | 6a98754 | 2007-01-07 07:40:09 +0000 | [diff] [blame^] | 65 | Function *FibF = |
| 66 | cast<Function>(M->getOrInsertFunction("fib", Type::Int32Ty, Type::Int32Ty, |
| 67 | (Type *)0)); |
Jeff Cohen | 00b16889 | 2005-07-27 06:12:32 +0000 | [diff] [blame] | 68 | |
Reid Spencer | e8cdc8b | 2005-07-12 21:51:33 +0000 | [diff] [blame] | 69 | // Add a basic block to the function. |
| 70 | BasicBlock *BB = new BasicBlock("EntryBlock", FibF); |
Jeff Cohen | 00b16889 | 2005-07-27 06:12:32 +0000 | [diff] [blame] | 71 | |
Reid Spencer | e8cdc8b | 2005-07-12 21:51:33 +0000 | [diff] [blame] | 72 | // Get pointers to the constants. |
Reid Spencer | db8d2be | 2006-12-31 05:50:28 +0000 | [diff] [blame] | 73 | Value *One = ConstantInt::get(Type::Int32Ty, 1); |
| 74 | Value *Two = ConstantInt::get(Type::Int32Ty, 2); |
Jeff Cohen | 00b16889 | 2005-07-27 06:12:32 +0000 | [diff] [blame] | 75 | |
Reid Spencer | e8cdc8b | 2005-07-12 21:51:33 +0000 | [diff] [blame] | 76 | // Get pointer to the integer argument of the add1 function... |
| 77 | Argument *ArgX = FibF->arg_begin(); // Get the arg. |
| 78 | ArgX->setName("AnArg"); // Give it a nice symbolic name for fun. |
Jeff Cohen | 00b16889 | 2005-07-27 06:12:32 +0000 | [diff] [blame] | 79 | |
Reid Spencer | e8cdc8b | 2005-07-12 21:51:33 +0000 | [diff] [blame] | 80 | // Create the true_block. |
| 81 | BasicBlock *RetBB = new BasicBlock("return", FibF); |
| 82 | // Create an exit block. |
| 83 | BasicBlock* RecurseBB = new BasicBlock("recurse", FibF); |
Jeff Cohen | 00b16889 | 2005-07-27 06:12:32 +0000 | [diff] [blame] | 84 | |
Reid Spencer | e8cdc8b | 2005-07-12 21:51:33 +0000 | [diff] [blame] | 85 | // Create the "if (arg < 2) goto exitbb" |
Reid Spencer | e4d87aa | 2006-12-23 06:05:41 +0000 | [diff] [blame] | 86 | Value *CondInst = new ICmpInst(ICmpInst::ICMP_SLE, ArgX, Two, "cond", BB); |
Reid Spencer | e8cdc8b | 2005-07-12 21:51:33 +0000 | [diff] [blame] | 87 | new BranchInst(RetBB, RecurseBB, CondInst, BB); |
Jeff Cohen | 00b16889 | 2005-07-27 06:12:32 +0000 | [diff] [blame] | 88 | |
Reid Spencer | e8cdc8b | 2005-07-12 21:51:33 +0000 | [diff] [blame] | 89 | // Create: ret int 1 |
| 90 | new ReturnInst(One, RetBB); |
Jeff Cohen | 00b16889 | 2005-07-27 06:12:32 +0000 | [diff] [blame] | 91 | |
Reid Spencer | e8cdc8b | 2005-07-12 21:51:33 +0000 | [diff] [blame] | 92 | // create fib(x-1) |
| 93 | Value *Sub = BinaryOperator::createSub(ArgX, One, "arg", RecurseBB); |
| 94 | Value *CallFibX1 = new CallInst(FibF, Sub, "fibx1", RecurseBB); |
Jeff Cohen | 00b16889 | 2005-07-27 06:12:32 +0000 | [diff] [blame] | 95 | |
Reid Spencer | e8cdc8b | 2005-07-12 21:51:33 +0000 | [diff] [blame] | 96 | // create fib(x-2) |
| 97 | Sub = BinaryOperator::createSub(ArgX, Two, "arg", RecurseBB); |
| 98 | Value *CallFibX2 = new CallInst(FibF, Sub, "fibx2", RecurseBB); |
Jeff Cohen | 00b16889 | 2005-07-27 06:12:32 +0000 | [diff] [blame] | 99 | |
Reid Spencer | e8cdc8b | 2005-07-12 21:51:33 +0000 | [diff] [blame] | 100 | // fib(x-1)+fib(x-2) |
Jeff Cohen | 00b16889 | 2005-07-27 06:12:32 +0000 | [diff] [blame] | 101 | Value *Sum = |
Reid Spencer | e8cdc8b | 2005-07-12 21:51:33 +0000 | [diff] [blame] | 102 | BinaryOperator::createAdd(CallFibX1, CallFibX2, "addresult", RecurseBB); |
Jeff Cohen | 00b16889 | 2005-07-27 06:12:32 +0000 | [diff] [blame] | 103 | |
Reid Spencer | e8cdc8b | 2005-07-12 21:51:33 +0000 | [diff] [blame] | 104 | // Create the return instruction and add it to the basic block |
| 105 | new ReturnInst(Sum, RecurseBB); |
Jeff Cohen | 00b16889 | 2005-07-27 06:12:32 +0000 | [diff] [blame] | 106 | |
Reid Spencer | e8cdc8b | 2005-07-12 21:51:33 +0000 | [diff] [blame] | 107 | return FibF; |
| 108 | } |
| 109 | |
| 110 | struct threadParams { |
| 111 | ExecutionEngine* EE; |
| 112 | Function* F; |
| 113 | int value; |
| 114 | }; |
| 115 | |
| 116 | // We block the subthreads just before they begin to execute: |
| 117 | // we want all of them to call into the JIT at the same time, |
| 118 | // to verify that the locking is working correctly. |
| 119 | class WaitForThreads |
| 120 | { |
| 121 | public: |
| 122 | WaitForThreads() |
| 123 | { |
| 124 | n = 0; |
| 125 | waitFor = 0; |
Jeff Cohen | 00b16889 | 2005-07-27 06:12:32 +0000 | [diff] [blame] | 126 | |
Reid Spencer | e8cdc8b | 2005-07-12 21:51:33 +0000 | [diff] [blame] | 127 | int result = pthread_cond_init( &condition, NULL ); |
| 128 | assert( result == 0 ); |
Jeff Cohen | 00b16889 | 2005-07-27 06:12:32 +0000 | [diff] [blame] | 129 | |
Reid Spencer | e8cdc8b | 2005-07-12 21:51:33 +0000 | [diff] [blame] | 130 | result = pthread_mutex_init( &mutex, NULL ); |
| 131 | assert( result == 0 ); |
| 132 | } |
Jeff Cohen | 00b16889 | 2005-07-27 06:12:32 +0000 | [diff] [blame] | 133 | |
Reid Spencer | e8cdc8b | 2005-07-12 21:51:33 +0000 | [diff] [blame] | 134 | ~WaitForThreads() |
| 135 | { |
| 136 | int result = pthread_cond_destroy( &condition ); |
| 137 | assert( result == 0 ); |
Jeff Cohen | 00b16889 | 2005-07-27 06:12:32 +0000 | [diff] [blame] | 138 | |
Reid Spencer | e8cdc8b | 2005-07-12 21:51:33 +0000 | [diff] [blame] | 139 | result = pthread_mutex_destroy( &mutex ); |
| 140 | assert( result == 0 ); |
| 141 | } |
Jeff Cohen | 00b16889 | 2005-07-27 06:12:32 +0000 | [diff] [blame] | 142 | |
Reid Spencer | e8cdc8b | 2005-07-12 21:51:33 +0000 | [diff] [blame] | 143 | // All threads will stop here until another thread calls releaseThreads |
| 144 | void block() |
| 145 | { |
| 146 | int result = pthread_mutex_lock( &mutex ); |
| 147 | assert( result == 0 ); |
| 148 | n ++; |
| 149 | //~ std::cout << "block() n " << n << " waitFor " << waitFor << std::endl; |
Jeff Cohen | 00b16889 | 2005-07-27 06:12:32 +0000 | [diff] [blame] | 150 | |
Reid Spencer | e8cdc8b | 2005-07-12 21:51:33 +0000 | [diff] [blame] | 151 | assert( waitFor == 0 || n <= waitFor ); |
Jeff Cohen | 00b16889 | 2005-07-27 06:12:32 +0000 | [diff] [blame] | 152 | if ( waitFor > 0 && n == waitFor ) |
Reid Spencer | e8cdc8b | 2005-07-12 21:51:33 +0000 | [diff] [blame] | 153 | { |
| 154 | // There are enough threads blocked that we can release all of them |
| 155 | std::cout << "Unblocking threads from block()" << std::endl; |
| 156 | unblockThreads(); |
Jeff Cohen | 00b16889 | 2005-07-27 06:12:32 +0000 | [diff] [blame] | 157 | } |
| 158 | else |
Reid Spencer | e8cdc8b | 2005-07-12 21:51:33 +0000 | [diff] [blame] | 159 | { |
| 160 | // We just need to wait until someone unblocks us |
| 161 | result = pthread_cond_wait( &condition, &mutex ); |
| 162 | assert( result == 0 ); |
| 163 | } |
Jeff Cohen | 00b16889 | 2005-07-27 06:12:32 +0000 | [diff] [blame] | 164 | |
Reid Spencer | e8cdc8b | 2005-07-12 21:51:33 +0000 | [diff] [blame] | 165 | // unlock the mutex before returning |
| 166 | result = pthread_mutex_unlock( &mutex ); |
| 167 | assert( result == 0 ); |
| 168 | } |
Jeff Cohen | 00b16889 | 2005-07-27 06:12:32 +0000 | [diff] [blame] | 169 | |
Reid Spencer | e8cdc8b | 2005-07-12 21:51:33 +0000 | [diff] [blame] | 170 | // If there are num or more threads blocked, it will signal them all |
| 171 | // Otherwise, this thread blocks until there are enough OTHER threads |
| 172 | // blocked |
| 173 | void releaseThreads( size_t num ) |
| 174 | { |
| 175 | int result = pthread_mutex_lock( &mutex ); |
| 176 | assert( result == 0 ); |
Jeff Cohen | 00b16889 | 2005-07-27 06:12:32 +0000 | [diff] [blame] | 177 | |
Reid Spencer | e8cdc8b | 2005-07-12 21:51:33 +0000 | [diff] [blame] | 178 | if ( n >= num ) { |
| 179 | std::cout << "Unblocking threads from releaseThreads()" << std::endl; |
| 180 | unblockThreads(); |
Jeff Cohen | 00b16889 | 2005-07-27 06:12:32 +0000 | [diff] [blame] | 181 | } |
| 182 | else |
Reid Spencer | e8cdc8b | 2005-07-12 21:51:33 +0000 | [diff] [blame] | 183 | { |
| 184 | waitFor = num; |
| 185 | pthread_cond_wait( &condition, &mutex ); |
| 186 | } |
Jeff Cohen | 00b16889 | 2005-07-27 06:12:32 +0000 | [diff] [blame] | 187 | |
Reid Spencer | e8cdc8b | 2005-07-12 21:51:33 +0000 | [diff] [blame] | 188 | // unlock the mutex before returning |
| 189 | result = pthread_mutex_unlock( &mutex ); |
| 190 | assert( result == 0 ); |
| 191 | } |
Jeff Cohen | 00b16889 | 2005-07-27 06:12:32 +0000 | [diff] [blame] | 192 | |
Reid Spencer | e8cdc8b | 2005-07-12 21:51:33 +0000 | [diff] [blame] | 193 | private: |
| 194 | void unblockThreads() |
| 195 | { |
| 196 | // Reset the counters to zero: this way, if any new threads |
| 197 | // enter while threads are exiting, they will block instead |
| 198 | // of triggering a new release of threads |
| 199 | n = 0; |
Jeff Cohen | 00b16889 | 2005-07-27 06:12:32 +0000 | [diff] [blame] | 200 | |
Reid Spencer | e8cdc8b | 2005-07-12 21:51:33 +0000 | [diff] [blame] | 201 | // Reset waitFor to zero: this way, if waitFor threads enter |
| 202 | // while threads are exiting, they will block instead of |
| 203 | // triggering a new release of threads |
| 204 | waitFor = 0; |
| 205 | |
| 206 | int result = pthread_cond_broadcast( &condition ); |
| 207 | assert( result == 0 ); |
| 208 | } |
Jeff Cohen | 00b16889 | 2005-07-27 06:12:32 +0000 | [diff] [blame] | 209 | |
Reid Spencer | e8cdc8b | 2005-07-12 21:51:33 +0000 | [diff] [blame] | 210 | size_t n; |
| 211 | size_t waitFor; |
| 212 | pthread_cond_t condition; |
| 213 | pthread_mutex_t mutex; |
| 214 | }; |
| 215 | |
| 216 | static WaitForThreads synchronize; |
| 217 | |
| 218 | void* callFunc( void* param ) |
| 219 | { |
| 220 | struct threadParams* p = (struct threadParams*) param; |
Jeff Cohen | 00b16889 | 2005-07-27 06:12:32 +0000 | [diff] [blame] | 221 | |
Reid Spencer | e8cdc8b | 2005-07-12 21:51:33 +0000 | [diff] [blame] | 222 | // Call the `foo' function with no arguments: |
| 223 | std::vector<GenericValue> Args(1); |
Reid Spencer | db8d2be | 2006-12-31 05:50:28 +0000 | [diff] [blame] | 224 | Args[0].Int32Val = p->value; |
Jeff Cohen | 00b16889 | 2005-07-27 06:12:32 +0000 | [diff] [blame] | 225 | |
Reid Spencer | e8cdc8b | 2005-07-12 21:51:33 +0000 | [diff] [blame] | 226 | synchronize.block(); // wait until other threads are at this point |
| 227 | GenericValue gv = p->EE->runFunction(p->F, Args); |
Jeff Cohen | 00b16889 | 2005-07-27 06:12:32 +0000 | [diff] [blame] | 228 | |
Reid Spencer | db8d2be | 2006-12-31 05:50:28 +0000 | [diff] [blame] | 229 | return (void*) intptr_t(gv.Int32Val); |
Reid Spencer | e8cdc8b | 2005-07-12 21:51:33 +0000 | [diff] [blame] | 230 | } |
| 231 | |
Jeff Cohen | 00b16889 | 2005-07-27 06:12:32 +0000 | [diff] [blame] | 232 | int main() |
Reid Spencer | e8cdc8b | 2005-07-12 21:51:33 +0000 | [diff] [blame] | 233 | { |
| 234 | // Create some module to put our function into it. |
| 235 | Module *M = new Module("test"); |
Jeff Cohen | 00b16889 | 2005-07-27 06:12:32 +0000 | [diff] [blame] | 236 | |
Reid Spencer | e8cdc8b | 2005-07-12 21:51:33 +0000 | [diff] [blame] | 237 | Function* add1F = createAdd1( M ); |
| 238 | Function* fibF = CreateFibFunction( M ); |
Jeff Cohen | 00b16889 | 2005-07-27 06:12:32 +0000 | [diff] [blame] | 239 | |
Reid Spencer | e8cdc8b | 2005-07-12 21:51:33 +0000 | [diff] [blame] | 240 | // Now we create the JIT. |
| 241 | ExistingModuleProvider* MP = new ExistingModuleProvider(M); |
| 242 | ExecutionEngine* EE = ExecutionEngine::create(MP, false); |
Jeff Cohen | 00b16889 | 2005-07-27 06:12:32 +0000 | [diff] [blame] | 243 | |
Reid Spencer | e8cdc8b | 2005-07-12 21:51:33 +0000 | [diff] [blame] | 244 | //~ std::cout << "We just constructed this LLVM module:\n\n" << *M; |
| 245 | //~ std::cout << "\n\nRunning foo: " << std::flush; |
Jeff Cohen | 00b16889 | 2005-07-27 06:12:32 +0000 | [diff] [blame] | 246 | |
Reid Spencer | e8cdc8b | 2005-07-12 21:51:33 +0000 | [diff] [blame] | 247 | // Create one thread for add1 and two threads for fib |
| 248 | struct threadParams add1 = { EE, add1F, 1000 }; |
| 249 | struct threadParams fib1 = { EE, fibF, 39 }; |
| 250 | struct threadParams fib2 = { EE, fibF, 42 }; |
Jeff Cohen | 00b16889 | 2005-07-27 06:12:32 +0000 | [diff] [blame] | 251 | |
Reid Spencer | e8cdc8b | 2005-07-12 21:51:33 +0000 | [diff] [blame] | 252 | pthread_t add1Thread; |
| 253 | int result = pthread_create( &add1Thread, NULL, callFunc, &add1 ); |
| 254 | if ( result != 0 ) { |
| 255 | std::cerr << "Could not create thread" << std::endl; |
| 256 | return 1; |
| 257 | } |
Jeff Cohen | 00b16889 | 2005-07-27 06:12:32 +0000 | [diff] [blame] | 258 | |
Reid Spencer | e8cdc8b | 2005-07-12 21:51:33 +0000 | [diff] [blame] | 259 | pthread_t fibThread1; |
| 260 | result = pthread_create( &fibThread1, NULL, callFunc, &fib1 ); |
| 261 | if ( result != 0 ) { |
| 262 | std::cerr << "Could not create thread" << std::endl; |
| 263 | return 1; |
| 264 | } |
Jeff Cohen | 00b16889 | 2005-07-27 06:12:32 +0000 | [diff] [blame] | 265 | |
Reid Spencer | e8cdc8b | 2005-07-12 21:51:33 +0000 | [diff] [blame] | 266 | pthread_t fibThread2; |
| 267 | result = pthread_create( &fibThread2, NULL, callFunc, &fib2 ); |
| 268 | if ( result != 0 ) { |
| 269 | std::cerr << "Could not create thread" << std::endl; |
| 270 | return 1; |
| 271 | } |
Jeff Cohen | 00b16889 | 2005-07-27 06:12:32 +0000 | [diff] [blame] | 272 | |
Reid Spencer | e8cdc8b | 2005-07-12 21:51:33 +0000 | [diff] [blame] | 273 | synchronize.releaseThreads(3); // wait until other threads are at this point |
Jeff Cohen | 00b16889 | 2005-07-27 06:12:32 +0000 | [diff] [blame] | 274 | |
Reid Spencer | e8cdc8b | 2005-07-12 21:51:33 +0000 | [diff] [blame] | 275 | void* returnValue; |
| 276 | result = pthread_join( add1Thread, &returnValue ); |
| 277 | if ( result != 0 ) { |
| 278 | std::cerr << "Could not join thread" << std::endl; |
| 279 | return 1; |
| 280 | } |
Reid Spencer | 6fb0d73 | 2005-07-13 23:20:24 +0000 | [diff] [blame] | 281 | std::cout << "Add1 returned " << intptr_t(returnValue) << std::endl; |
Jeff Cohen | 00b16889 | 2005-07-27 06:12:32 +0000 | [diff] [blame] | 282 | |
Reid Spencer | e8cdc8b | 2005-07-12 21:51:33 +0000 | [diff] [blame] | 283 | result = pthread_join( fibThread1, &returnValue ); |
| 284 | if ( result != 0 ) { |
| 285 | std::cerr << "Could not join thread" << std::endl; |
| 286 | return 1; |
| 287 | } |
Reid Spencer | 6fb0d73 | 2005-07-13 23:20:24 +0000 | [diff] [blame] | 288 | std::cout << "Fib1 returned " << intptr_t(returnValue) << std::endl; |
Jeff Cohen | 00b16889 | 2005-07-27 06:12:32 +0000 | [diff] [blame] | 289 | |
Reid Spencer | e8cdc8b | 2005-07-12 21:51:33 +0000 | [diff] [blame] | 290 | result = pthread_join( fibThread2, &returnValue ); |
| 291 | if ( result != 0 ) { |
| 292 | std::cerr << "Could not join thread" << std::endl; |
| 293 | return 1; |
| 294 | } |
Reid Spencer | 6fb0d73 | 2005-07-13 23:20:24 +0000 | [diff] [blame] | 295 | std::cout << "Fib2 returned " << intptr_t(returnValue) << std::endl; |
Jeff Cohen | 00b16889 | 2005-07-27 06:12:32 +0000 | [diff] [blame] | 296 | |
Reid Spencer | e8cdc8b | 2005-07-12 21:51:33 +0000 | [diff] [blame] | 297 | return 0; |
| 298 | } |