Page MenuHomePhorge

D115.1732489018.diff
No OneTemporary

Size
2 KB
Referenced Files
None
Subscribers
None

D115.1732489018.diff

diff --git a/tutorials/tutorial0.md b/tutorials/tutorial0.md
--- a/tutorials/tutorial0.md
+++ b/tutorials/tutorial0.md
@@ -147,7 +147,7 @@
> SomeClass::someMethod()
> {
> m_client.someOperation()
-> .then([=] {
+> .then([=](auto stat) {
> // Bad
> m_client.someOtherOperation();
> });
@@ -157,8 +157,47 @@
> The code above is bad because, it is possible that the instance of `SomeClass` may
> have been destroyed by the time the callback is actually run. And thus, `m_client`,
> which is acutally `(capturedThis)->m_client`, is a dereferencing of a dangling
-> pointer. This will give you a segmentation fault as a result. It is suggested to
-> explicitly capture `m_client` by changing `[=]` to `[m_client=m_client]`.
+> pointer. This will give you a segmentation fault as a result.
+> Also, the `Client` class, together with all classes that deals
+> with lager cursors, belongs to some thread. (In general,
+> you should not be calling the methods on an object that
+> does not belong to the current thread, unless it is documented
+> safe to do so. See https://github.com/arximboldi/lager/issues/118
+> and the documentation for `Client` for more details.)
+> libkazv offers a check when it is compiled with
+> `-DCMAKE_BUILD_TYPE=Debug`. This checks if the current thread
+> calling a method of `Client` is the same thread that this
+> `Client` belongs to. If not, it will throw an exception.
+> This check will prevent you from accidentally calling
+> some method in a different thread than the expected one.
+>
+> ```
+> SomeClass::someMethod()
+> {
+> m_client.someOperation()
+> .then([client=m_client](auto stat) {
+> // ALSO bad: although this does not suffer from
+> // free-after-use problems, there are thread-safety
+> // problems if someMethod() is not called from
+> // the same thread as the event loop.
+> client.someOtherOperation();
+> });
+> }
+> ```
+>
+> Instead, you should use the `toEventLoop()` function if
+> you are passing a `Client` into an async callback:
+>
+> ```
+> SomeClass::someMethod()
+> {
+> m_client.someOperation()
+> .then([client=toEventLoop()](auto stat) {
+> // Good
+> client.someOtherOperation();
+> });
+> }
+> ```
```
io.run();

File Metadata

Mime Type
text/plain
Expires
Sun, Nov 24, 2:56 PM (9 h, 28 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
39914
Default Alt Text
D115.1732489018.diff (2 KB)

Event Timeline