Changeset 433 for pjproject/trunk/pjlib/src/pjlib-test/thread.c
- Timestamp:
- May 10, 2006 7:24:40 PM (18 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
pjproject/trunk/pjlib/src/pjlib-test/thread.c
r351 r433 53 53 #define THIS_FILE "thread_test" 54 54 55 static int quit_flag=0; 55 static volatile int quit_flag=0; 56 57 #if 0 58 # define TRACE__(args) PJ_LOG(3,args) 59 #else 60 # define TRACE__(args) 61 #endif 62 56 63 57 64 /* … … 66 73 pj_thread_desc desc; 67 74 pj_thread_t *this_thread; 75 unsigned id = *pcounter; 68 76 pj_status_t rc; 77 78 TRACE__((THIS_FILE, " thread %d running..", id)); 69 79 70 80 rc = pj_thread_register("thread", desc, &this_thread); … … 91 101 (*pcounter)++; 92 102 //Must sleep if platform doesn't do time-slicing. 93 pj_thread_sleep(0); 94 } 95 103 //pj_thread_sleep(0); 104 } 105 106 TRACE__((THIS_FILE, " thread %d quitting..", id)); 96 107 return NULL; 97 108 } … … 115 126 quit_flag = 0; 116 127 128 TRACE__((THIS_FILE, " Creating thread 0..")); 117 129 rc = pj_thread_create(pool, "thread", (pj_thread_proc*)&thread_proc, 118 130 &counter, … … 126 138 } 127 139 128 pj_thread_sleep(500); 140 TRACE__((THIS_FILE, " Main thread waiting..")); 141 pj_thread_sleep(1500); 142 TRACE__((THIS_FILE, " Main thread resuming..")); 129 143 130 144 if (flags & PJ_THREAD_SUSPENDED) { … … 145 159 PJ_LOG(3,(THIS_FILE, "..waiting for thread to quit..")); 146 160 147 pj_thread_sleep( 500);161 pj_thread_sleep(1500); 148 162 149 163 quit_flag = 1; … … 176 190 quit_flag = 0; 177 191 178 pool = pj_pool_create(mem, NULL, 40 96,0, NULL);192 pool = pj_pool_create(mem, NULL, 4000, 4000, NULL); 179 193 if (!pool) 180 194 return -10; … … 184 198 /* Create all threads in suspended mode. */ 185 199 for (i=0; i<NUM_THREADS; ++i) { 186 counter[i] = 0;200 counter[i] = i; 187 201 rc = pj_thread_create(pool, "thread", (pj_thread_proc*)&thread_proc, 188 202 &counter[i], … … 199 213 * The purpose of this is to test whether all threads are suspended. 200 214 */ 215 TRACE__((THIS_FILE, " Main thread waiting..")); 201 216 pj_thread_sleep(1000); 217 TRACE__((THIS_FILE, " Main thread resuming..")); 202 218 203 219 /* Check that all counters are still zero. */ 204 220 for (i=0; i<NUM_THREADS; ++i) { 205 if (counter[i] != 0) {221 if (counter[i] > i) { 206 222 PJ_LOG(3,(THIS_FILE, "....ERROR! Thread %d-th is not suspended!", 207 223 i)); … … 212 228 /* Now resume all threads. */ 213 229 for (i=0; i<NUM_THREADS; ++i) { 230 TRACE__((THIS_FILE, " Resuming thread %d [%p]..", i, thread[i])); 214 231 rc = pj_thread_resume(thread[i]); 215 232 if (rc != PJ_SUCCESS) { … … 223 240 * but it'll make user waits for longer for the test to finish. 224 241 */ 242 TRACE__((THIS_FILE, " Main thread waiting (5s)..")); 225 243 pj_thread_sleep(5000); 244 TRACE__((THIS_FILE, " Main thread resuming..")); 226 245 227 246 /* Signal all threads to quit. */ … … 230 249 /* Wait until all threads quit, then destroy. */ 231 250 for (i=0; i<NUM_THREADS; ++i) { 251 TRACE__((THIS_FILE, " Main thread joining thread %d [%p]..", 252 i, thread[i])); 232 253 rc = pj_thread_join(thread[i]); 233 254 if (rc != PJ_SUCCESS) { … … 235 256 return -50; 236 257 } 258 TRACE__((THIS_FILE, " Destroying thread %d [%p]..", i, thread[i])); 237 259 rc = pj_thread_destroy(thread[i]); 238 260 if (rc != PJ_SUCCESS) { … … 241 263 } 242 264 } 265 266 TRACE__((THIS_FILE, " Main thread calculating time slices..")); 243 267 244 268 /* Now examine the value of the counters. … … 264 288 diff = (highest-lowest)*100 / ((highest+lowest)/2); 265 289 if ( diff >= 50) { 266 PJ_LOG(3,(THIS_FILE, "...ERROR: thread didn't have equal timeslice!")); 267 PJ_LOG(3,(THIS_FILE, ".....lowest counter=%u, highest counter=%u, diff=%u%%", 268 lowest, highest, diff)); 290 PJ_LOG(3,(THIS_FILE, 291 "...ERROR: thread didn't have equal timeslice!")); 292 PJ_LOG(3,(THIS_FILE, 293 ".....lowest counter=%u, highest counter=%u, diff=%u%%", 294 lowest, highest, diff)); 269 295 return -80; 270 296 } else { … … 274 300 } 275 301 302 pj_pool_release(pool); 276 303 return 0; 277 304 }
Note: See TracChangeset
for help on using the changeset viewer.