[Xapian-tickets] [Xapian] #788: Thread safe move semantics
Xapian
nobody at xapian.org
Mon Jun 10 15:57:03 BST 2019
#788: Thread safe move semantics
---------------------------+------------------
Reporter: Kronuz | Owner: olly
Type: defect | Status: new
Priority: high | Milestone:
Component: Other | Version:
Severity: normal | Keywords:
Blocked By: | Blocking:
Operating System: All |
---------------------------+------------------
When using move semantics (using `std::move`), not all objects are really
moved. For example, `Document` and `Database`; instead use
`intrusive_ptr_nonnull`'s move constructor which essentially just
increments the reference counter and copies the pointer `px`. This doesn't
cut it when one needs to move objects from one thread to other; reason is
this produces a race condition in the reference counter, in which both
threads could be modifying the non-atomic counter simultaneously.
What I did instead (in Xapiand) is I'm using a so called
`internal_intrusive_ptr` which ensures an object with an "internal" type
still remains valid (and with a valid, non-null `px`) after moving away
it's original content. Implementation uses a `tmp`, from which it extracts
the newly created "empty" internal `px` and can be seen here:
https://github.com/Kronuz/Xapiand/commit/33ccddbdaa1e3a24a68700af24cf3c7562f43621
#diff-bedbbf7159a3d537faadbb10befc15ceR375
This `internal_intrusive_ptr` could be used everywhere where
`intrusive_ptr_nonnull` is used ''if'' the object in question has a
default constructor, such as:
* `Database`
* `Document`
* `ESet`
* `MSet`
* `QueryParser`
* `Registry`
* `TermGenerator`
--
Ticket URL: <https://trac.xapian.org/ticket/788>
Xapian <https://xapian.org/>
Xapian
More information about the Xapian-tickets
mailing list