comparison src/parallel_execution/main.c @ 123:4ff6f093b695

Fix segmentation fault
author Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
date Tue, 13 Sep 2016 11:54:25 +0900
parents a086857e1812
children acf0453b1c7a
comparison
equal deleted inserted replaced
122:a086857e1812 123:4ff6f093b695
205 } 205 }
206 206
207 __code createTask3(struct Context* context, struct Allocate* allocate) { 207 __code createTask3(struct Context* context, struct Allocate* allocate) {
208 allocate->size = sizeof(struct Task); 208 allocate->size = sizeof(struct Task);
209 allocator(context); 209 allocator(context);
210 goto meta(context, CreateTask2); 210 goto meta(context, CreateTask4);
211 } 211 }
212 212
213 __code createTask3_stub(struct Context* context) { 213 __code createTask3_stub(struct Context* context) {
214 goto createTask1(context, &context->data[Allocate]->allocate); 214 goto createTask3(context, &context->data[Allocate]->allocate);
215 } 215 }
216 216
217 217
218 __code createTask4(struct Context* context, struct LoopCounter* loopCounter, struct Task* task, struct Element* element, struct Node* node) { 218 __code createTask4(struct Context* context, struct LoopCounter* loopCounter, struct Task* task, struct Element* element) {
219 int i = loopCounter->i; 219 int i = loopCounter->i;
220 220
221 task->code = Add; 221 task->code = Add;
222 task->oKeys[0] = i; 222 task->oKeys[0] = i;
223 task->iKeys[0] = i-1; 223 task->iKeys[0] = i-1;
224 task->iKeys[1] = i-2; 224 task->iKeys[1] = i-2;
225 loopCounter->i -= 2; 225 loopCounter->i -= 2;
226 element->data = (union Data *)task; 226 element->data = (union Data *)task;
227 context->next = WaitFor; 227 context->next = CreateTask5;
228
229 node->key = task->oKeys[0];
230 goto meta(context, Get); 228 goto meta(context, Get);
231 } 229 }
232 230
233 __code createTask4_stub(struct Context* context) { 231 __code createTask4_stub(struct Context* context) {
234 goto createTask4(context, 232 goto createTask4(context,
235 &context->data[LoopCounter]->loopCounter, 233 &context->data[LoopCounter]->loopCounter,
236 &context->data[context->dataNum]->task, 234 &context->data[context->dataNum]->task,
237 &context->data[Element]->element, 235 &context->data[Element]->element
238 &context->data[Node]->node); 236 );
237 }
238
239 __code createTask5(struct Context* context, struct Task* task, struct Node* node) {
240 node->key = task->oKeys[0];
241 loopCounter->i = 0;
242 context->next = Code1;
243 goto meta(context, WaitFor);
244 }
245
246 __code createTask5_stub(struct Context* context) {
247 goto createTask4(context,
248 &context->data[LoopCounter]->loopCounter,
249 &context->data[context->dataNum]->task,
250 &context->data[Node]->node
251 );
239 } 252 }
240 253
241 __code putQueue1(struct Context* context, struct Allocate* allocate) { 254 __code putQueue1(struct Context* context, struct Allocate* allocate) {
242 allocate->size = sizeof(struct Element); 255 allocate->size = sizeof(struct Element);
243 allocator(context); 256 allocator(context);
322 goto createWorker(context, &context->data[LoopCounter]->loopCounter, &context->data[Worker]->worker); 335 goto createWorker(context, &context->data[LoopCounter]->loopCounter, &context->data[Worker]->worker);
323 } 336 }
324 337
325 __code taskManager(struct Context* context, struct LoopCounter* loopCounter, struct Worker* worker, struct Queue* waitQueue, struct Queue* ActiveQueue) { 338 __code taskManager(struct Context* context, struct LoopCounter* loopCounter, struct Worker* worker, struct Queue* waitQueue, struct Queue* ActiveQueue) {
326 if (waitQueue->first) { 339 if (waitQueue->first) {
327 goto meta(context, Poll1); 340 goto meta(context, Poll1);
328 } 341 }
329 int i = loopCounter->i; 342 int i = loopCounter->i;
330 if (i < worker->num) { 343 if (i < worker->num) {
331 pthread_join(worker->contexts[i].thread, NULL); 344 pthread_join(worker->contexts[i].thread, NULL);
332 loopCounter->i++; 345 loopCounter->i++;
351 context->data[Queue] = (union Data *)queue; 364 context->data[Queue] = (union Data *)queue;
352 goto (context->code[next])(context); 365 goto (context->code[next])(context);
353 } 366 }
354 367
355 __code poll1(struct Context* context, struct Queue* waitQueue) { 368 __code poll1(struct Context* context, struct Queue* waitQueue) {
369 usleep(100);
356 context->next = Poll2; 370 context->next = Poll2;
357 goto meta_poll1(context, waitQueue, GetQueue1); 371 goto meta_poll1(context, waitQueue, GetQueue1);
358 } 372 }
359 373
360 __code poll1_stub(struct Context* context) { 374 __code poll1_stub(struct Context* context) {