aboutsummaryrefslogtreecommitdiff
path: root/src/scheduler.h
diff options
context:
space:
mode:
authorMarcoFalke <falke.marco@gmail.com>2018-07-31 20:50:18 -0400
committerMarcoFalke <falke.marco@gmail.com>2018-07-31 20:52:05 -0400
commite83d82a85c53196aff5b5ac500f20bb2940663fa (patch)
treec58c2d14bdcc61e149d2b5739de0eb5034820d8a /src/scheduler.h
parent0fb9c87815d180031b7924607946e51f860c3ba8 (diff)
parentcbeaa91dbb1bc3ee6c05f3ee55a71268b8db2035 (diff)
Merge #13247: Add tests to SingleThreadedSchedulerClient() and document the memory model
cbeaa91dbb Update ValidationInterface() documentation to explicitly specify threading and memory model (Jesse Cohen) b296b425a7 Update documentation for SingleThreadedSchedulerClient() to specify the memory model (Jesse Cohen) 9994d01d8b Add Unit Test for SingleThreadedSchedulerClient (Jesse Cohen) Pull request description: As discussed in #13023 I've split this test out into a separate pr This test (and documentation update) makes explicit the guarantee (previously undefined, but implied by the 'SingleThreaded' in `SingleThreadedSchedulerClient()`) - that callbacks pushed to the `SingleThreadedSchedulerClient()` obey the single threaded model for memory and execution - specifically, the callbacks are executed fully and in order, and even in cases where a subsequent callback is executed by a different thread, sequential consistency of memory for all threads executing these callbacks is maintained. Maintaining memory consistency should make the api more developer friendly - especially for users of the validationinterface. To the extent that there are performance implications from this decision, these are not currently present in practice because all use of this scheduler happens on a single thread currently, furthermore the lock should guarantee consistency across callback executions even when callbacks are executed by multiple threads (as the test does). Tree-SHA512: 5d95a7682c402e5ad76b05bc9dfbca99ca64105f62ab9e78f6fc0f6ea8c5277aa399fbb94298e35cc677b0c2181ff17259584bb7ae230e38aa68b85ecbc22856
Diffstat (limited to 'src/scheduler.h')
-rw-r--r--src/scheduler.h17
1 files changed, 14 insertions, 3 deletions
diff --git a/src/scheduler.h b/src/scheduler.h
index 7169dceee5..421002ec17 100644
--- a/src/scheduler.h
+++ b/src/scheduler.h
@@ -86,9 +86,13 @@ private:
/**
* Class used by CScheduler clients which may schedule multiple jobs
- * which are required to be run serially. Does not require such jobs
- * to be executed on the same thread, but no two jobs will be executed
- * at the same time.
+ * which are required to be run serially. Jobs may not be run on the
+ * same thread, but no two jobs will be executed
+ * at the same time and memory will be release-acquire consistent
+ * (the scheduler will internally do an acquire before invoking a callback
+ * as well as a release at the end). In practice this means that a callback
+ * B() will be able to observe all of the effects of callback A() which executed
+ * before it.
*/
class SingleThreadedSchedulerClient {
private:
@@ -103,6 +107,13 @@ private:
public:
explicit SingleThreadedSchedulerClient(CScheduler *pschedulerIn) : m_pscheduler(pschedulerIn) {}
+
+ /**
+ * Add a callback to be executed. Callbacks are executed serially
+ * and memory is sequentially consistent between callback executions.
+ * Practially, this means that callbacks can behave as if they are executed
+ * in order by a single thread.
+ */
void AddToProcessQueue(std::function<void (void)> func);
// Processes all remaining queue members on the calling thread, blocking until queue is empty