Skip to content

Commit

Permalink
comments
Browse files Browse the repository at this point in the history
  • Loading branch information
fchn289 committed Aug 5, 2024
1 parent cea8204 commit 6447cd0
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 8 deletions.
9 changes: 6 additions & 3 deletions src/thread/AsyncBack.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,10 @@
// * ONLY call AsyncBack in main-thread
//
//
// - Use-safe: yes with condition:
// . not support TOO many threads (used-up thread resource; impossible in most/normal cases)
// . lower performance than eg thread pool (but simpler impl than thread pool)
// . destructor will FOREVER wait all thread finished
// - MT safe: NO
// * all AsyncBack func (include ThreadBack) must run in 1 thread (best in main thread)
// . AsyncBack can call inMyMainTH() to ensure this
Expand All @@ -47,9 +51,6 @@
// . no duty to any unsafe behavior of MT_TaskEntryFN & TaskBackFN (eg throw exception)
// . MT_TaskEntryFN & TaskBackFN shall NOT throw exception
// . they can try-catch all exception & leave rlib simple/focus
// - Use-safe: LTD
// . not support too many threads (used-up thread resource; impossible in most/normal cases)
// . lower performance than eg thread pool (but simpler impl than thread pool)
//
// - support multi-thread
// . MT_/mt_ prefix: yes
Expand All @@ -65,6 +66,8 @@ namespace rlib
class AsyncBack : public ThreadBack
{
public:
// destruct-future will block till thread done (ut verified) - so default ~AsyncBack() is safe

bool newTaskOK(const MT_TaskEntryFN&, const TaskBackFN&, UniLog& = UniLog::defaultUniLog_) override;
};

Expand Down
5 changes: 3 additions & 2 deletions src/thread/ThPoolBack.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,11 @@
// - avoid create/destroy thread, 10~100 faster than AsyncBack
// - code more complex than AsyncBack
//
// Use-safe: yes with condition:
// - not support TOO many tasks that exceeds fut_backFN_S_/nDoneTh_/.. (impossible in most/normal cases)
// - destructor will FOREVER wait all thread finished
// MT safe: NO (can be used in main thread only)
// Exception-safe: NO
// Use-safe: yes with condition:
// - shall not too many tasks that exceeds fut_backFN_S_/nDoneTh_/.. (impossible in most/normal cases)
// ***********************************************************************************************
#pragma once

Expand Down
6 changes: 3 additions & 3 deletions ut/thread/ThPoolBackTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ TEST_F(ThPoolBackTest, invalid_maxThread)
// ***********************************************************************************************
TEST_F(ThPoolBackTest, performance)
{
const size_t maxThread = 10; // github ci can afford 100 (1000+ slower than belinb03)
const size_t maxThread = 10; // github ci can afford 10 (1000+ slower than belinb03)

ThPoolBack thPoolBack(maxThread);
auto start = high_resolution_clock::now();
Expand All @@ -38,8 +38,8 @@ TEST_F(ThPoolBackTest, performance)
timedwait();
auto dur = duration_cast<chrono::microseconds>(high_resolution_clock::now() - start);
HID("ThPoolBack cost=" << dur.count() << "us");
// - belinb03 : ~ 20 faster than AsyncBack
// - github ci: ~100 slower than AsyncBack
// - belinb03 : 8~ 20 faster than AsyncBack
// - github ci: 40~100 slower than AsyncBack

AsyncBack asyncBack;
start = high_resolution_clock::now();
Expand Down

0 comments on commit 6447cd0

Please sign in to comment.