From bdf1b724289fec7dd8f257ada89d74286ed5884e Mon Sep 17 00:00:00 2001 From: Bowen Fu Date: Sun, 10 Jul 2022 14:56:24 +0800 Subject: [PATCH 01/15] MVar --- include/hspp.h | 37 ++++++++++-- test/hspp/stm.cpp | 150 +++++++++++++++++++++++++++++++++++++++++----- 2 files changed, 169 insertions(+), 18 deletions(-) diff --git a/include/hspp.h b/include/hspp.h index a2c8789..9c3853e 100644 --- a/include/hspp.h +++ b/include/hspp.h @@ -1262,18 +1262,32 @@ template constexpr static auto isIOV = IsIO>::value; template -auto io(Func func) +constexpr auto io(Func func) { using Data = std::invoke_result_t; - return IO{func}; + return IO{std::move(func)}; } template -auto ioData(Data data) +constexpr auto ioData(Data data) { return io([data=std::move(data)] { return data; }); } +template +constexpr auto toTEIOImpl(IO const& p) +{ + return IO{[p]{ + return p.run(); + }}; +} + +constexpr auto toTEIO = toGFunc<1> | [](auto p) +{ + return toTEIOImpl(p); +}; + + constexpr auto putChar = toFunc<> | [](char c) { return io( @@ -3577,6 +3591,13 @@ class IsNullary> : public std::true_type template constexpr auto isNullary = IsNullary>::value; +template , void>> +constexpr auto evalDeferredImpl(T&& t) +{ + static_assert(std::is_same_v, MonadType>>); + return t(); +} + template class IsNullaryOrId : public IsNullary { @@ -3825,7 +3846,15 @@ template constexpr auto do_(Head const& head, Rest const&... rest) { using MClass = MonadClassType; - return doImpl(head, rest...); + auto result = doImpl(head, rest...); + static_assert(!isNullaryOrIdV); + return result; +} + +template +constexpr auto doInner(Args&&... args) +{ + return nullary([=] { return do_(evaluate_(args)...); }); } template diff --git a/test/hspp/stm.cpp b/test/hspp/stm.cpp index 7e62823..466ffff 100644 --- a/test/hspp/stm.cpp +++ b/test/hspp/stm.cpp @@ -51,22 +51,22 @@ TEST(forkIO, 1) io_.run(); } -TEST(forkIO, 2) +constexpr auto setReminder = toFunc<> | [](std::string const& s) { - auto setReminder = toFunc<> | [](std::string const& s) - { - Id n; - return do_( - n = (hspp::read | s), - putStr | "Ok, I'll remind you in ", - print | n, - putStrLn | " seconds", - threadDelay | (1000000U * n), - print | n, - putStrLn | " seconds is up! BING!BEL" - ); - }; + Id n; + return do_( + n = (hspp::read | s), // let expression. + putStr | "Ok, I'll remind you in ", + print | n, + putStrLn | " seconds", + threadDelay | (1000000U * n), + print | n, + putStrLn | " seconds is up! BING!BEL" + ); +}; +TEST(forkIO, 2) +{ Id s; auto io_ = forever || do_( s <= getLine, @@ -74,7 +74,129 @@ TEST(forkIO, 2) ); // io.run(); (void)io_; + +} + +TEST(forkIO, 3) +{ + IO<_O_> loop0 = []{ return _o_; }; + auto loop = loop0; + + Id s; + loop = toTEIO | do_( + s <= getLine, + ifThenElse(s == "exit") + || loop0 + || toTEIO | (doInner(forkIO || setReminder | s, + nullary([&]{ return loop;}))) // capturing by ref is important, so that loop is not fixed to loop0. + ); + + loop.run(); +} + +template +struct MVar +{ + std::shared_ptr>> data = std::make_shared>>(); +}; + +template +constexpr auto newEmptyMVar = io([]{ return MVar{}; }); + +template +constexpr auto newMVarImpl(A a) +{ + return io([&]{ return MVar{std::move(a)}; }); +} + +constexpr auto newMVar = toGFunc<1> | [](auto a) +{ + return newMVarImpl(a); +}; + +template +constexpr auto takeMVarImpl(MVar const& a) +{ + return io([a] + { + std::optional result{}; + do { + std::this_thread::yield(); + result = a.data->exchange(std::optional{}); + } while(!result.has_value()); + return result.value(); + }); +} + +constexpr auto takeMVar = toGFunc<1> | [](auto a) +{ + return takeMVarImpl(a); +}; + +template +constexpr auto putMVarImpl(MVar& a, A new_) +{ + return io([a, new_=std::make_optional(std::move(new_))] + { + std::optional old{}; + while (!a.data->compare_exchange_weak(old, new_)) + { + std::this_thread::yield(); + } + return _o_; + }); +} + +constexpr auto putMVar = toGFunc<2> | [](auto a, auto new_) +{ + return putMVarImpl(a, new_); +}; + +TEST(MVar, 1) +{ + (void)newMVar; + + Id> m; + Id r; + auto const io_ = do_( + m <= newEmptyMVar, + forkIO || putMVar | m | 'x', + r <= (takeMVar | m), + print | r + ); + io_.run(); +} + +TEST(MVar, 2) +{ + Id> m; + Id r; + auto io_ = do_( + m <= newEmptyMVar, + forkIO || doInner( + putMVar | m | 'x', + putMVar | m | 'y' + ), + r <= (takeMVar | m), + print | r, + r <= (takeMVar | m), + print | r + ); + io_.run(); +} + +// stuck +#if 0 +TEST(MVar, 3) +{ + Id> m; + auto io_ = do_( + m <= newEmptyMVar, + takeMVar | m + ); + io_.run(); } +#endif template struct IORef From b6da8c0429bac965fb8411e8dde064b37d7e1b14 Mon Sep 17 00:00:00 2001 From: Bowen Fu Date: Sun, 10 Jul 2022 15:01:11 +0800 Subject: [PATCH 02/15] Fix tests --- test/hspp/stm.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/test/hspp/stm.cpp b/test/hspp/stm.cpp index 466ffff..599e755 100644 --- a/test/hspp/stm.cpp +++ b/test/hspp/stm.cpp @@ -91,7 +91,8 @@ TEST(forkIO, 3) nullary([&]{ return loop;}))) // capturing by ref is important, so that loop is not fixed to loop0. ); - loop.run(); + // loop.run(); + (void)loop; } template From eb54c93cd614b81a55c771bad99578436b10ecc0 Mon Sep 17 00:00:00 2001 From: Bowen Fu Date: Sun, 10 Jul 2022 15:08:52 +0800 Subject: [PATCH 03/15] Fix tests --- test/hspp/CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/hspp/CMakeLists.txt b/test/hspp/CMakeLists.txt index 13c37ff..65f1566 100644 --- a/test/hspp/CMakeLists.txt +++ b/test/hspp/CMakeLists.txt @@ -1,6 +1,6 @@ add_executable(unittests test.cpp stm.cpp) target_include_directories(unittests PRIVATE) target_compile_options(unittests PRIVATE ${BASE_COMPILE_FLAGS}) -target_link_libraries(unittests PRIVATE hspp gtest_main) +target_link_libraries(unittests PRIVATE hspp gtest_main atomic) set_target_properties(unittests PROPERTIES CXX_EXTENSIONS OFF) gtest_discover_tests(unittests) \ No newline at end of file From f25be29988c7909996161fca2a97011a9bd55b71 Mon Sep 17 00:00:00 2001 From: Bowen Fu Date: Sun, 10 Jul 2022 15:22:56 +0800 Subject: [PATCH 04/15] Fix atomic --- CMakeLists.txt | 5 +++++ test/hspp/CMakeLists.txt | 2 +- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index ac1b764..67a0635 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -20,6 +20,11 @@ list(APPEND "$<$,$,$>:-Wall;-Wextra;-pedantic;-Werror;-Wno-parentheses;-Wno-shadow;-Wconversion;-Wsign-conversion>" "$<$:/W4>") # /WX for -Werror +# Fix atomic lib linking for gcc. +list(APPEND + BASE_COMPILE_FLAGS + "$<$>:-latomic>") + set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/bin) set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/lib) set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/lib) diff --git a/test/hspp/CMakeLists.txt b/test/hspp/CMakeLists.txt index 65f1566..13c37ff 100644 --- a/test/hspp/CMakeLists.txt +++ b/test/hspp/CMakeLists.txt @@ -1,6 +1,6 @@ add_executable(unittests test.cpp stm.cpp) target_include_directories(unittests PRIVATE) target_compile_options(unittests PRIVATE ${BASE_COMPILE_FLAGS}) -target_link_libraries(unittests PRIVATE hspp gtest_main atomic) +target_link_libraries(unittests PRIVATE hspp gtest_main) set_target_properties(unittests PROPERTIES CXX_EXTENSIONS OFF) gtest_discover_tests(unittests) \ No newline at end of file From cac9d1f2bb144e72a17601bcd6b4ff7f1faf4054 Mon Sep 17 00:00:00 2001 From: Bowen Fu Date: Sun, 10 Jul 2022 15:25:50 +0800 Subject: [PATCH 05/15] Fix atomic --- CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 67a0635..be77529 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -23,7 +23,7 @@ list(APPEND # Fix atomic lib linking for gcc. list(APPEND BASE_COMPILE_FLAGS - "$<$>:-latomic>") + "$<$:$>:-latomic>") set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/bin) set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/lib) From 2c053b5db3102427393650380a5bd42c1a11d1c2 Mon Sep 17 00:00:00 2001 From: Bowen Fu Date: Sun, 10 Jul 2022 15:26:48 +0800 Subject: [PATCH 06/15] Fix atomic --- CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index be77529..7de28a8 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -23,7 +23,7 @@ list(APPEND # Fix atomic lib linking for gcc. list(APPEND BASE_COMPILE_FLAGS - "$<$:$>:-latomic>") + "$<$,$>:-latomic>") set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/bin) set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/lib) From 893eb4085e1ae6444b1a7dab9914e23dc24569e9 Mon Sep 17 00:00:00 2001 From: Bowen Fu Date: Sun, 10 Jul 2022 15:28:22 +0800 Subject: [PATCH 07/15] Fix atomic --- CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 7de28a8..67a0635 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -23,7 +23,7 @@ list(APPEND # Fix atomic lib linking for gcc. list(APPEND BASE_COMPILE_FLAGS - "$<$,$>:-latomic>") + "$<$>:-latomic>") set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/bin) set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/lib) From 566818b5517b0053720c789f423d23bc0cb2dfc5 Mon Sep 17 00:00:00 2001 From: Bowen Fu Date: Sun, 10 Jul 2022 15:47:51 +0800 Subject: [PATCH 08/15] Fix atomic --- CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 67a0635..7de28a8 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -23,7 +23,7 @@ list(APPEND # Fix atomic lib linking for gcc. list(APPEND BASE_COMPILE_FLAGS - "$<$>:-latomic>") + "$<$,$>:-latomic>") set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/bin) set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/lib) From f972782d4b96227cb1a538b3c52c904ee973dbdb Mon Sep 17 00:00:00 2001 From: Bowen Fu Date: Sun, 10 Jul 2022 16:13:08 +0800 Subject: [PATCH 09/15] Fix atomic --- CMakeLists.txt | 2 +- test/hspp/CMakeLists.txt | 1 + test/hspp/stm.cpp | 39 +++++++++++++++++++++++++++++++++++---- 3 files changed, 37 insertions(+), 5 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 7de28a8..1b35047 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -22,7 +22,7 @@ list(APPEND # Fix atomic lib linking for gcc. list(APPEND - BASE_COMPILE_FLAGS + BASE_LINK_FLAGS "$<$,$>:-latomic>") set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/bin) diff --git a/test/hspp/CMakeLists.txt b/test/hspp/CMakeLists.txt index 13c37ff..a906bd7 100644 --- a/test/hspp/CMakeLists.txt +++ b/test/hspp/CMakeLists.txt @@ -2,5 +2,6 @@ add_executable(unittests test.cpp stm.cpp) target_include_directories(unittests PRIVATE) target_compile_options(unittests PRIVATE ${BASE_COMPILE_FLAGS}) target_link_libraries(unittests PRIVATE hspp gtest_main) +add_link_options($BASE_LINK_FLAGS) set_target_properties(unittests PROPERTIES CXX_EXTENSIONS OFF) gtest_discover_tests(unittests) \ No newline at end of file diff --git a/test/hspp/stm.cpp b/test/hspp/stm.cpp index 599e755..487b8c7 100644 --- a/test/hspp/stm.cpp +++ b/test/hspp/stm.cpp @@ -186,8 +186,6 @@ TEST(MVar, 2) io_.run(); } -// stuck -#if 0 TEST(MVar, 3) { Id> m; @@ -195,9 +193,42 @@ TEST(MVar, 3) m <= newEmptyMVar, takeMVar | m ); - io_.run(); + // stuck + (void)io_; + // io_.run(); +} + +#if 0 +class Message : public std::string{}; +class Stop : public MVar<_O_>{}; + +using LogCommand = std::variant; +class Logger : public MVar{}; + +constexpr auto logger(Logger& l) +{ + auto loop = + where + loop = do_( + cmd <= (takeMVar | m), + case cmd of + Message msg -> doInner(putStrLn | msg, loop), + Stop s -> doInner(putStrLn | "logger: stop", putMVar | s | _o_) + ); +} + +constexpr auto initLoggerImpl() +{ + Id m; + Id l; + return do_( + m <= newEmptyMVar, + l = (Logger | m), + forkIO | (logger | l), + return_ | l + ); } -#endif +#endif // 0 template struct IORef From 7ca733cf7567259b734be18f3e9da9a2146cb622 Mon Sep 17 00:00:00 2001 From: Bowen Fu Date: Sun, 10 Jul 2022 16:43:45 +0800 Subject: [PATCH 10/15] Fix linker --- CMakeLists.txt | 2 +- include/hspp.h | 11 +++++++++++ test/hspp/stm.cpp | 29 +++++++++++++++++++++-------- 3 files changed, 33 insertions(+), 9 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 1b35047..7256a34 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -23,7 +23,7 @@ list(APPEND # Fix atomic lib linking for gcc. list(APPEND BASE_LINK_FLAGS - "$<$,$>:-latomic>") + "$<$,$>:-latomic;-v>") set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/bin) set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/lib) diff --git a/include/hspp.h b/include/hspp.h index 9c3853e..26120f8 100644 --- a/include/hspp.h +++ b/include/hspp.h @@ -3578,6 +3578,17 @@ constexpr auto nullary(T const &t) return Nullary{t}; } +template +constexpr auto toTENullaryImpl(Nullary const &t) +{ + return nullary(std::function>{t}); +} + +constexpr auto toTENullary = toGFunc<1> | [](auto const& t) +{ + return toTENullaryImpl(t); +}; + template class IsNullary : public std::false_type { diff --git a/test/hspp/stm.cpp b/test/hspp/stm.cpp index 487b8c7..8c5050c 100644 --- a/test/hspp/stm.cpp +++ b/test/hspp/stm.cpp @@ -205,15 +205,28 @@ class Stop : public MVar<_O_>{}; using LogCommand = std::variant; class Logger : public MVar{}; -constexpr auto logger(Logger& l) + +auto logger(Logger& m) { - auto loop = - where - loop = do_( + IO<_O_> loop0 = []{ return _o_; }; + auto loop = loop0; + + auto const dispatchCmd = toFunc<> | [&loop](LogCommand const& lc) + { + return std::visit(overload( + [&](Message const& msg){ + return toTEIO | do_(print | msg, loop); + }, + [](Stop s){ + return toTEIO | do_(putStrLn | "logger: stop", putMVar | s | _o_); + } + ), lc); + }; + + Id cmd; + loop = toTEIO | do_( cmd <= (takeMVar | m), - case cmd of - Message msg -> doInner(putStrLn | msg, loop), - Stop s -> doInner(putStrLn | "logger: stop", putMVar | s | _o_) + dispatchCmd | cmd ); } @@ -222,7 +235,7 @@ constexpr auto initLoggerImpl() Id m; Id l; return do_( - m <= newEmptyMVar, + m <= newEmptyMVar, l = (Logger | m), forkIO | (logger | l), return_ | l From 8663d73927c881129f9f2c152a11687ea3b5a05e Mon Sep 17 00:00:00 2001 From: Bowen Fu Date: Sun, 10 Jul 2022 17:12:05 +0800 Subject: [PATCH 11/15] Fix linker --- CMakeLists.txt | 4 ++-- include/hspp.h | 6 +++--- test/hspp/CMakeLists.txt | 4 +--- 3 files changed, 6 insertions(+), 8 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 7256a34..051fc22 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -22,8 +22,8 @@ list(APPEND # Fix atomic lib linking for gcc. list(APPEND - BASE_LINK_FLAGS - "$<$,$>:-latomic;-v>") + BASE_ADDITIONAL_LIBS + "$<$,$>:atomic>") set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/bin) set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/lib) diff --git a/include/hspp.h b/include/hspp.h index 26120f8..07b9fb6 100644 --- a/include/hspp.h +++ b/include/hspp.h @@ -2677,7 +2677,7 @@ class Functor template constexpr static auto fmap(Func&& func, data::Reader const& in) { - return data::toReader | func (data::runReader | in); + return data::toReader || func (data::runReader | in); } }; @@ -2846,12 +2846,12 @@ class Applicative : public Functor | [](auto ret) { - return data::toReader | data::toFunc<>([ret=std::move(ret)](FirstArg){ return ret; }); + return data::toReader || data::toFunc<>([ret=std::move(ret)](FirstArg){ return ret; }); }; template constexpr static auto ap(Reader1 func, Reader1 in) { - return data::toReader | data::toFunc<>( + return data::toReader || data::toFunc<>( [func=std::move(func), in=std::move(in)](FirstArg arg) { return data::runReader | func | arg || data::runReader | in | arg; diff --git a/test/hspp/CMakeLists.txt b/test/hspp/CMakeLists.txt index a906bd7..145486e 100644 --- a/test/hspp/CMakeLists.txt +++ b/test/hspp/CMakeLists.txt @@ -1,7 +1,5 @@ add_executable(unittests test.cpp stm.cpp) target_include_directories(unittests PRIVATE) -target_compile_options(unittests PRIVATE ${BASE_COMPILE_FLAGS}) -target_link_libraries(unittests PRIVATE hspp gtest_main) -add_link_options($BASE_LINK_FLAGS) +target_link_libraries(unittests PRIVATE hspp gtest_main ${BASE_ADDITIONAL_LIBS}) set_target_properties(unittests PROPERTIES CXX_EXTENSIONS OFF) gtest_discover_tests(unittests) \ No newline at end of file From 0e9b7789011d77bca8b9ab6016bc05c387e954ae Mon Sep 17 00:00:00 2001 From: Bowen Fu Date: Sun, 10 Jul 2022 17:58:34 +0800 Subject: [PATCH 12/15] Fix mvar --- test/hspp/stm.cpp | 42 ++++++++++++++++++++++++++++++++---------- 1 file changed, 32 insertions(+), 10 deletions(-) diff --git a/test/hspp/stm.cpp b/test/hspp/stm.cpp index 8c5050c..2ada786 100644 --- a/test/hspp/stm.cpp +++ b/test/hspp/stm.cpp @@ -98,9 +98,16 @@ TEST(forkIO, 3) template struct MVar { - std::shared_ptr>> data = std::make_shared>>(); + using T = std::pair, std::mutex>; + std::shared_ptr data = std::make_shared(); + MVar() = default; + MVar(A a) + : data{std::make_shared(a, {})} + {} }; +static_assert(std::atomic>::is_always_lock_free); + template constexpr auto newEmptyMVar = io([]{ return MVar{}; }); @@ -120,12 +127,20 @@ constexpr auto takeMVarImpl(MVar const& a) { return io([a] { - std::optional result{}; - do { + while (true) + { + if (a.data->first.has_value()) + { + std::unique_lock lock{a.data->second}; + if (a.data->first.has_value()) + { + auto result = std::move(a.data->first.value()); + a.data->first.reset(); + return result; + } + } std::this_thread::yield(); - result = a.data->exchange(std::optional{}); - } while(!result.has_value()); - return result.value(); + } }); } @@ -137,14 +152,21 @@ constexpr auto takeMVar = toGFunc<1> | [](auto a) template constexpr auto putMVarImpl(MVar& a, A new_) { - return io([a, new_=std::make_optional(std::move(new_))] + return io([a, new_] { - std::optional old{}; - while (!a.data->compare_exchange_weak(old, new_)) + while (true) { + if (!a.data->first.has_value()) + { + std::unique_lock lock{a.data->second}; + if (!a.data->first.has_value()) + { + a.data->first = new_; + return _o_; + } + } std::this_thread::yield(); } - return _o_; }); } From ce24063bfd52a97782a9663d8df00cc50a1056c6 Mon Sep 17 00:00:00 2001 From: Bowen Fu Date: Sun, 10 Jul 2022 18:03:08 +0800 Subject: [PATCH 13/15] Fix mvar --- test/hspp/stm.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/test/hspp/stm.cpp b/test/hspp/stm.cpp index 2ada786..3d00e81 100644 --- a/test/hspp/stm.cpp +++ b/test/hspp/stm.cpp @@ -6,6 +6,7 @@ #include #include #include +#include using namespace hspp; using namespace hspp::data; @@ -98,7 +99,7 @@ TEST(forkIO, 3) template struct MVar { - using T = std::pair, std::mutex>; + using T = std::pair, std::shared_mutex>; std::shared_ptr data = std::make_shared(); MVar() = default; MVar(A a) From c2e6147fd0a7c210388b1fe2392639bf616fa117 Mon Sep 17 00:00:00 2001 From: Bowen Fu Date: Sun, 10 Jul 2022 18:13:30 +0800 Subject: [PATCH 14/15] Fix mvar --- test/hspp/stm.cpp | 2 -- 1 file changed, 2 deletions(-) diff --git a/test/hspp/stm.cpp b/test/hspp/stm.cpp index 3d00e81..5fea3c6 100644 --- a/test/hspp/stm.cpp +++ b/test/hspp/stm.cpp @@ -107,8 +107,6 @@ struct MVar {} }; -static_assert(std::atomic>::is_always_lock_free); - template constexpr auto newEmptyMVar = io([]{ return MVar{}; }); From 88dc38102c14e814b292352ff1ea53ea25e7576a Mon Sep 17 00:00:00 2001 From: Bowen Fu Date: Sun, 10 Jul 2022 18:18:07 +0800 Subject: [PATCH 15/15] Fix mvar --- test/hspp/stm.cpp | 2 -- 1 file changed, 2 deletions(-) diff --git a/test/hspp/stm.cpp b/test/hspp/stm.cpp index 5fea3c6..f4d134b 100644 --- a/test/hspp/stm.cpp +++ b/test/hspp/stm.cpp @@ -128,7 +128,6 @@ constexpr auto takeMVarImpl(MVar const& a) { while (true) { - if (a.data->first.has_value()) { std::unique_lock lock{a.data->second}; if (a.data->first.has_value()) @@ -155,7 +154,6 @@ constexpr auto putMVarImpl(MVar& a, A new_) { while (true) { - if (!a.data->first.has_value()) { std::unique_lock lock{a.data->second}; if (!a.data->first.has_value())