| 1429 | }; |
| 1430 | |
| 1431 | static ThreadState *newThread(void *(*thread_func)(ThreadState *, void *), |
| 1432 | void *arg, const char **error) { |
| 1433 | ThreadState *ts = NULL; |
| 1434 | if (error) *error = NULL; |
| 1435 | thread_lock.lock(); |
| 1436 | for (int i=0; i<MAX_THREADS; i++) { |
| 1437 | if (!thread_state[i].active) { |
| 1438 | ts = thread_state + i; |
| 1439 | ts->index = i; |
| 1440 | ts->parent = pthread_self(); |
| 1441 | ts->active = true; |
| 1442 | ts->running = true; |
| 1443 | ts->to_thread = queue<string>(); |
| 1444 | ts->from_thread = queue<string>(); |
| 1445 | ts->thread_func = thread_func; |
| 1446 | ts->arg = arg; |
| 1447 | ts->result = NULL; |
| 1448 | if (pthread_create(&ts->id, NULL, thread_main, ts)<0) { |
| 1449 | if (error) |
| 1450 | *error = "createThread: internal error: failed to create thread"; |
| 1451 | goto fail; |
| 1452 | } |
| 1453 | goto exit; |
| 1454 | } |
| 1455 | } |
| 1456 | if (error) *error = "createThread: too many threads"; |
| 1457 | fail: |
| 1458 | ts = NULL; |
| 1459 | exit: |
| 1460 | thread_lock.unlock(); |
| 1461 | return ts; |
| 1462 | } |
| 1463 | |
| 1464 | ThreadState *createThread(void *(*thread_func)(ThreadState *, void *), |
| 1465 | void *arg) { |
no test coverage detected