| 437 | } |
| 438 | |
| 439 | void test_multi_threaded_order(bool use_pthread) { |
| 440 | memset(next_task, 0, sizeof(next_task)); |
| 441 | long disorder_times = 0; |
| 442 | bthread::ExecutionQueueId<LongIntTask> queue_id = { 0 }; // to suppress warnings |
| 443 | bthread::ExecutionQueueOptions options; |
| 444 | options.use_pthread = use_pthread; |
| 445 | if (options.use_pthread) { |
| 446 | LOG(INFO) << "================ pthread ================"; |
| 447 | } else { |
| 448 | LOG(INFO) << "================ bthread ================"; |
| 449 | } |
| 450 | ASSERT_EQ(0, bthread::execution_queue_start(&queue_id, &options, |
| 451 | check_order, &disorder_times)); |
| 452 | pthread_t threads[12]; |
| 453 | for (size_t i = 0; i < ARRAY_SIZE(threads); ++i) { |
| 454 | pthread_create(&threads[i], NULL, &push_thread_with_id, (void *)queue_id.value); |
| 455 | } |
| 456 | for (size_t i = 0; i < ARRAY_SIZE(threads); ++i) { |
| 457 | pthread_join(threads[i], NULL); |
| 458 | } |
| 459 | ASSERT_EQ(0, bthread::execution_queue_stop(queue_id)); |
| 460 | ASSERT_EQ(0, bthread::execution_queue_join(queue_id)); |
| 461 | ASSERT_EQ(0, disorder_times); |
| 462 | } |
| 463 | |
| 464 | TEST_F(ExecutionQueueTest, multi_threaded_order) { |
| 465 | for (int i = 0; i < 2; ++i) { |
no test coverage detected