* @brief Check that detach_task() or submit_task() work. * * @param which_func A string naming the function to check. */
| 883 | * @param which_func A string naming the function to check. |
| 884 | */ |
| 885 | void check_task(const std::string_view which_func) |
| 886 | { |
| 887 | BS::thread_pool pool; |
| 888 | logln("Checking that ", which_func, " works for a function with no arguments or return value..."); |
| 889 | { |
| 890 | bool flag = false; |
| 891 | const auto func = [&flag] |
| 892 | { |
| 893 | flag = true; |
| 894 | }; |
| 895 | if (which_func == "detach_task()") |
| 896 | { |
| 897 | pool.detach_task(func); |
| 898 | pool.wait(); |
| 899 | } |
| 900 | else |
| 901 | { |
| 902 | pool.submit_task(func).wait(); |
| 903 | } |
| 904 | check(flag); |
| 905 | } |
| 906 | logln("Checking that ", which_func, " works for a function with one argument and no return value..."); |
| 907 | { |
| 908 | bool flag = false; |
| 909 | const auto func = [](bool& flag_) |
| 910 | { |
| 911 | flag_ = true; |
| 912 | }; |
| 913 | if (which_func == "detach_task()") |
| 914 | { |
| 915 | pool.detach_task( |
| 916 | [&func, &flag] |
| 917 | { |
| 918 | func(flag); |
| 919 | }); |
| 920 | pool.wait(); |
| 921 | } |
| 922 | else |
| 923 | { |
| 924 | pool.submit_task( |
| 925 | [&func, &flag] |
| 926 | { |
| 927 | func(flag); |
| 928 | }) |
| 929 | .wait(); |
| 930 | } |
| 931 | check(flag); |
| 932 | } |
| 933 | logln("Checking that ", which_func, " works for a function with two arguments and no return value..."); |
| 934 | { |
| 935 | bool flag1 = false; |
| 936 | bool flag2 = false; |
| 937 | const auto func = [](bool& flag1_, bool& flag2_) |
| 938 | { |
| 939 | flag1_ = flag2_ = true; |
| 940 | }; |
| 941 | if (which_func == "detach_task()") |
| 942 | { |
no test coverage detected