Ticket #19 (closed defect: invalid)

Opened 3 years ago

Last modified 4 days ago

Thread synchronization

Reported by: jtv Assigned to: jtv
Priority: high Milestone: 3.1
Component: other Version:
Severity: major Keywords:
Cc:

Description (Last modified by jtv)

The library still needs a flexible mechanism for thread synchronization, particularly when it comes to connections.

In most cases, concurrent const operations on objects don't interfere with one another and concurrent operations on one object often do not affect operations on another. The most notable exception is that many operations on other objects will interfere with the connection object they are related to.

To allow client programs to deal with this, a template parameter will be added to the basic_connection template that lets the client program specify a custom synchronization class. Options would include no-op synchronization for single-threaded programs; locking synchronization for complex multithreaded programs; and a cheap "debug class" that only detects and reports thread-safety errors.

Another, more awkward case is reference-counting in the PQAlloc-derived classes such as binarystring and result. This could be quite awkward; we'll have to look long and hard at possibilities for lock-free algorithms.

One low-overhead "synchronization" class could merely keep track of the last thread, function, or object to modify each protected object so as to detect race errors.

Attachments

Change History

01/07/06 13:50:53 changed by jtv

  • status changed from new to assigned.

02/11/06 04:07:49 changed by jtv

  • description changed.

09/06/06 23:50:43 changed by theo@crazygreek.co.uk

random thought:

Perhaps a pool of connections, that are locked when a transaction is in progress? Something like:

connection_pool pool("host=1.2.3.4 user=moo", <minConnections>, <maxConnections>);

{

/* assigns a connection from the pool and removes from the pool for the duration of the work */

work W(pool);

...

} // connection is now returned to the pool

...

not thought it through too much, but might be useful. Of course, handling prepared statements, noticers, triggers, could be a bit of a problem.

05/12/08 10:59:37 changed by jtv

  • cc deleted.
  • keywords deleted.

05/13/08 01:21:52 changed by jtv

  • version deleted.

11/02/08 01:38:47 changed by jtv

  • milestone changed from 3.0 to 3.1.

01/03/09 01:44:40 changed by jtv

  • status changed from assigned to closed.
  • resolution set to invalid.

Dealing with this differently, by documenting the threading model and using the thread-safe shared_ptr where available. Adding locking inside the library is likely to do more harm than good.

Closing this ticket, and opening new ones for remaining work.


Add/Change #19 (Thread synchronization)




Change Properties
Action