diff --git a/libs/pbd/pbd/stateful.h b/libs/pbd/pbd/stateful.h
index 2d5b2a0..30487c2 100644
--- a/libs/pbd/pbd/stateful.h
+++ b/libs/pbd/pbd/stateful.h
@@ -125,6 +125,9 @@ class Stateful {
 
   private:
 	PBD::ID  _id;
+
+	static std::set<PBD::ID> _used_ids;
+	static pthread_mutex_t* _used_ids_mutex;
 };
 
 } // namespace PBD
diff --git a/libs/pbd/stateful.cc b/libs/pbd/stateful.cc
index b2c76f4..65ae799 100644
--- a/libs/pbd/stateful.cc
+++ b/libs/pbd/stateful.cc
@@ -37,11 +37,18 @@ namespace PBD {
 
 int Stateful::current_state_version = 0;
 int Stateful::loading_state_version = 0;
+pthread_mutex_t* Stateful::_used_ids_mutex = 0;
+set<PBD::ID> Stateful::_used_ids;
 
 Stateful::Stateful ()
 	: _frozen (0)
 	, _properties (new OwnedPropertyList)
 {
+	if (_used_ids_mutex == 0) {
+		_used_ids_mutex = new pthread_mutex_t;
+		pthread_mutex_init (_used_ids_mutex, NULL);
+	}
+	
 	_extra_xml = 0;
 	_instant_xml = 0;
 }
@@ -375,7 +382,7 @@ Stateful::set_id (const XMLNode& node)
 	const XMLProperty* prop;
 
 	if ((prop = node.property ("id")) != 0) {
-		_id = prop->value ();
+		set_id (prop->value ());
 		return true;
 	} 
 
@@ -392,6 +399,11 @@ void
 Stateful::set_id (const string& str)
 {
 	_id = str;
+
+	pthread_mutex_lock (_used_ids_mutex);
+	assert (_used_ids.find (_id) == _used_ids.end ());
+	_used_ids.insert (_id);
+	pthread_mutex_unlock (_used_ids_mutex);
 }
 
 } // namespace PBD
