Skip to content

Commit cb28719

Browse files
committed
ThreadBack: comments
1 parent ded1cae commit cb28719

File tree

6 files changed

+16
-18
lines changed

6 files changed

+16
-18
lines changed

src/thread/AsyncBack.hpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@
3535
// * AsyncBack is for normal/most scenario, may NOK for huge threads, high throughput, etc
3636
// * ONLY call AsyncBack in main-thread
3737
//
38-
//
3938
// - Use-safe: yes with condition:
4039
// . not support TOO many threads (used-up thread resource; impossible in most/normal cases)
4140
// . lower performance than eg thread pool (but simpler impl than thread pool)
@@ -51,7 +50,6 @@
5150
// . no duty to any unsafe behavior of MT_TaskEntryFN & TaskBackFN (eg throw exception)
5251
// . MT_TaskEntryFN & TaskBackFN shall NOT throw exception
5352
// . they can try-catch all exception & leave rlib simple/focus
54-
//
5553
// - support multi-thread
5654
// . MT_/mt_ prefix: yes
5755
// . others: NO (only use in main thread - most dom lib code shall in main thread - simple & nsesilbe)

src/thread/ThPoolBack.hpp

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,16 @@
44
* SPDX-License-Identifier: BSD-3-Clause
55
*/
66
// ***********************************************************************************************
7-
// Why:
8-
// - alt AsyncBack by limit thread# (limited resource) but may wait more time for free thread
9-
// - avoid create/destroy thread, 10~100 faster than AsyncBack
10-
// - code more complex than AsyncBack
7+
// - Why:
8+
// . alt AsyncBack by limit thread# (limited resource) but may wait more time for free thread
9+
// . avoid create/destroy thread, 10~100 faster than AsyncBack
10+
// . code more complex than AsyncBack
1111
//
12-
// Use-safe: yes with condition:
13-
// - not support TOO many tasks that exceeds fut_backFN_S_/nDoneTh_/.. (impossible in most/normal cases)
14-
// - destructor will FOREVER wait all thread finished
15-
// MT safe: NO (can be used in main thread only)
16-
// Exception-safe: NO
12+
// - Use-safe: yes with condition:
13+
// . not support TOO many tasks that exceeds fut_backFN_S_/nDoneTh_/.. (impossible in most/normal cases)
14+
// . destructor will FOREVER wait all thread finished
15+
// - MT safe: NO (can be used in main thread only)
16+
// - Exception-safe: NO
1717
// ***********************************************************************************************
1818
#pragma once
1919

src/thread/ThreadBack.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ size_t ThreadBack::hdlFinishedTasks(UniLog& oneLog)
2525
// - async() failure will throw exception -> terminate since compiling forbid exception
2626
// - valid async()'s future never invalid
2727
// - valid packaged_task's get_future() never invalid
28-
auto&& fut = fut_backFN->first;
28+
auto& fut = fut_backFN->first;
2929
// HID("(ThreadBack) nHandled=" << nHandledTask << '/' << nFinishedTask
3030
// << ", valid=" << fut.valid() << ", backFn=" << &(fut_backFN->second));
3131
if (fut.wait_for(0s) == future_status::ready)

src/thread/ThreadBack.hpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,6 @@
77
// - Why this class:
88
// . support both async() & thread pool
99
// . common here, special in AsyncBack or ThPoolBack
10-
//
11-
// - why SafePtr
12-
// . thread can ret any type data include bool
13-
// . safe convert from SafePtr<void> to correct data
1410
// ***********************************************************************************************
1511
#pragma once
1612

@@ -72,3 +68,7 @@ class ThreadBack
7268
// 2024-08-05 CSZ - nDoneTh_ to improve iteration of fut_backFN_S_
7369
// - MT_TaskEntryFN ret SafePtr<void> instead of bool
7470
// ***********************************************************************************************
71+
// - why SafePtr
72+
// . thread can ret any type data include bool
73+
// . simpler than using MtQ to ship rsp back to main thread
74+
// . safe convert from SafePtr<void> to corresponding data

ut/thread/ThPoolBackTest.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ TEST_F(ThPoolBackTest, invalid_maxThread)
2121
// ***********************************************************************************************
2222
TEST_F(ThPoolBackTest, performance)
2323
{
24-
const size_t maxThread = 10; // github ci can afford 10 (1000+ slower than belinb03)
24+
const size_t maxThread = 100; // github ci can afford 100 (1000+ slower than belinb03)
2525

2626
ThPoolBack thPoolBack(maxThread);
2727
auto start = high_resolution_clock::now();

ut/thread/ThreadBackTest.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ TEST_F(THREAD_BACK_TEST, GOLD_entryFnResult_toBackFn_withoutTimedWait)
9696
));
9797
}
9898

99-
// REQ: no timedwait() but keep asking
99+
// REQ: no timedwait() but keep asking; cost most time in CI
100100
for (size_t nHandled = 0; nHandled < maxThread; nHandled += threadBack_.hdlFinishedTasks())
101101
{
102102
INF("nHandled=" << nHandled);

0 commit comments

Comments
 (0)