Skip to content

Draft: Improve Container thread safety in SIP

The idea is make sure that the Container is accessed/modified in a thread-safe way, that is with a lock to the mutex that protect the underlying std::map taken. The lock should be managed in RAII style, using a lock guard.

In Python, we need to implement the context manager protocol to make sure that iteration on the container is thread safe, while keeping backward compatibility with existing code:

with data.header as header:
  for k, v in header.iteritems():
      print(f'key={k}, value={v}')

The suggest solution works like this:

      // dump the content of a data HeaderContainer to a stream sout
      {
	Data::HeaderContainer::LockedPtr l_ptr(data.header);
        Data::HeaderContainer::iterator it, end = l_ptr->end();
	for (it = l_ptr->begin(); it != end; ++i)
	    sout << it->first << " = "
                 << (it->second.size() ? it->second : " ")
	         << ";" << std::endl;
      }
Edited by Samuel Debionne

Merge request reports

Loading