UnitTest for start/stop threaded update and fix
All checks were successful
Publish doxygen documentation to seodisparate.com / doxygen-gen-and-publish (push) Successful in 0s

This commit is contained in:
Stephen Seo 2024-01-11 20:07:25 +09:00
parent de2848004f
commit c03eae1c15
2 changed files with 29 additions and 1 deletions

View file

@ -2326,7 +2326,9 @@ void UDPC_destroy(UDPC_HContext ctx) {
// After lock has been dropped, wait in case there are enable/disable
// threaded update functions waiting on the lock. Do this via a
// atomic-int-based spin-lock.
while(UDPC_ctx->enableDisableFuncRunningCount.load() != 0) {}
while(UDPC_ctx->enableDisableFuncRunningCount.load() != 0) {
std::this_thread::sleep_for(std::chrono::milliseconds(10));
}
#if UDPC_PLATFORM == UDPC_PLATFORM_WINDOWS
WSACleanup();

View file

@ -434,3 +434,29 @@ TEST(UDPC, free_packet_ptr) {
UDPC_free_PacketInfo_ptr(&pinfo);
UDPC_free_PacketInfo_ptr(nullptr);
}
TEST(UDPC, enableDisableThreadedUpdate_StressTest) {
UDPC_ConnectionId id = UDPC_create_id_anyaddr(0);
UDPC_HContext ctx = UDPC_init(id, 0, 0);
std::array<std::thread, 100> thread_array;
for (int i = 0; i < 100; ++i) {
if (i % 2 == 0) {
thread_array[i] = std::thread([] (UDPC_HContext ctx) {
UDPC_enable_threaded_update(ctx);
}, ctx);
} else {
thread_array[i] = std::thread([] (UDPC_HContext ctx) {
UDPC_disable_threaded_update(ctx);
}, ctx);
}
}
thread_array[0].join();
UDPC_destroy(ctx);
for (int i = 1; i < 100; ++i) {
thread_array[i].join();
}
}