Ticket #1353 (closed: fixed)

Opened 10 years ago

Last modified 5 years ago

Improve thread-safety of cow_ptr

Reported by: Russell Taylor Owned by: Russell Taylor
Priority: major Milestone: Iteration 27
Component: Mantid Keywords:
Cc: Blocked By:
Blocking: Tester: Owen Arnold

Description

When vectors are shared between spectra and an algorithm is breaking that sharing, you can have a problem with the original vector being destroyed because the check for uniqueness in cow_ptr::access always fails if multiple threads are checking at the same time. I.e. the reference count goes from, e.g., 2 to zero if two threads go through simultaneously on their final pass.

Change History

comment:1 Changed 10 years ago by Russell Taylor

(In [5033]) Add critical section to cow_ptr::access method to prevent original vector being lost when sharing is broken. Appears to have no noticeable impact on speed. Re #1353.

comment:2 Changed 10 years ago by Russell Taylor

  • Status changed from new to accepted

comment:3 Changed 10 years ago by Russell Taylor

  • Status changed from accepted to testing
  • Resolution set to fixed

comment:4 Changed 10 years ago by Russell Taylor

  • Status changed from testing to reopened
  • Resolution fixed deleted

comment:5 Changed 10 years ago by Russell Taylor

(In [5078]) The changes to cow_ptr solved one issue, but not the one at hand which is that you can still wind up reading from a vector that's been/being written to by another thread. Re #1353.

comment:6 Changed 10 years ago by Nick Draper

  • Milestone changed from Iteration 26 to Iteration 27

Bulk move of tickets to iteration 27, if your ticket is essential for Iteration 26 then move it back.

comment:7 Changed 10 years ago by Russell Taylor

  • Status changed from reopened to accepted
  • Component set to Mantid

comment:8 Changed 10 years ago by Russell Taylor

  • Status changed from accepted to verify
  • Resolution set to fixed

This is partially fixed, but without bigger changes I think we just have to accept that care is needed when breaking sharing if input and output workspaces are the same.

i.e. code should look like this (dataX before readX).

MantidVec& xOut = outputWS->dataX(i); Make sure reference to input X vector is obtained after output one because in the case where the input & output workspaces are the same, it might move if the vectors were shared. const MantidVec& xIn = inputWS->readX(i);

comment:9 Changed 10 years ago by Russell Taylor

Try again to make code look right....

MantidVec& xOut = outputWS->dataX(i);
// Make sure reference to input X vector is obtained after output one because in the case  
// where the input & output workspaces are the same, it might move if the vectors were shared.
const MantidVec& xIn = inputWS->readX(i)

comment:10 Changed 10 years ago by Owen Arnold

  • Status changed from verify to verifying
  • Tester set to Owen Arnold

comment:11 Changed 10 years ago by Owen Arnold

  • Status changed from verifying to closed

Cannot set up threading schenario to verify that critical portion of the code is thread safe. Can verify that unit tests utilisting cow_ptrs pass such as test_LoadPreNexus, so unlikely to have broken core functionality.

comment:12 Changed 5 years ago by Stuart Campbell

This ticket has been transferred to github issue 2200

Note: See TracTickets for help on using tickets.