MCPcopy Create free account
hub / github.com/bshoshany/thread-pool / check_task

Function check_task

tests/BS_thread_pool_test.cpp:885–1113  ·  view source on GitHub ↗

* @brief Check that detach_task() or submit_task() work. * * @param which_func A string naming the function to check. */

Source from the content-addressed store, hash-verified

883 * @param which_func A string naming the function to check.
884 */
885void 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 {

Callers 1

mainFunction · 0.85

Calls 9

loglnFunction · 0.85
checkFunction · 0.85
detect_copy_moveClass · 0.85
waitMethod · 0.80
getMethod · 0.80
get_copiedMethod · 0.80
get_movedMethod · 0.80
acquireMethod · 0.80
releaseMethod · 0.80

Tested by

no test coverage detected