Page Menu
Home
Phorge
Search
Configure Global Search
Log In
Files
F113785
D115.1732489018.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Award Token
Flag For Later
Size
2 KB
Referenced Files
None
Subscribers
None
D115.1732489018.diff
View Options
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
Details
Attached
Mime Type
text/plain
Expires
Sun, Nov 24, 2:56 PM (11 h, 25 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
39914
Default Alt Text
D115.1732489018.diff (2 KB)
Attached To
Mode
D115: Update tutorial 0 to reflect thread-safety problems
Attached
Detach File
Event Timeline
Log In to Comment