Small corrections in SyncInterestTable
diff --git a/model/sync-interest-table.cc b/model/sync-interest-table.cc
index 0ec430c..b9f6484 100644
--- a/model/sync-interest-table.cc
+++ b/model/sync-interest-table.cc
@@ -28,52 +28,85 @@
 namespace Sync
 {
 
-vector<string> SyncInterestTable::fetchAll()
+SyncInterestTable::SyncInterestTable ()
+  : m_running (true)
 {
-	expireInterests();
-
-	recursive_mutex::scoped_lock lock(m_mutex);
-	vector<string> entries;
-	for (unordered_map<string, time_t>::iterator it = m_table.begin(); it !=
-		m_table.end(); ++it) {
-		entries.push_back(it->first);
-	}
-	m_table.clear();
-
-	return entries;
+  m_thread = thread (&SyncInterestTable::periodicCheck, this);
 }
 
-bool SyncInterestTable::insert(string interest)
+SyncInterestTable::~SyncInterestTable ()
 {
-	recursive_mutex::scoped_lock lock(m_mutex);
-	unordered_map<string, time_t>::iterator it = m_table.find(interest);
-	if (it != m_table.end())
-		m_table.erase(it);
-	time_t currentTime = time(0);
-	m_table.insert(make_pair(interest, currentTime));
+  // cout << "request interrupt: " << this_thread::get_id () << endl;
+  m_running = false;
+  m_thread.interrupt ();
+  m_thread.join ();
 }
 
-SyncInterestTable::SyncInterestTable() {
-	m_thread = thread(&SyncInterestTable::periodicCheck, this);
+vector<string>
+SyncInterestTable::fetchAll ()
+{
+  expireInterests();
+
+  recursive_mutex::scoped_lock lock (m_mutex);
+  
+  vector<string> entries;
+  for (unordered_map<string, time_t>::iterator it = m_table.begin();
+       it != m_table.end();
+       ++it)
+    {
+      entries.push_back(it->first);
+    }
+  m_table.clear ();
+
+  return entries;
 }
 
-void SyncInterestTable::expireInterests() {
-	recursive_mutex::scoped_lock lock(m_mutex);
-	time_t currentTime = time(0);
-	unordered_map<string, time_t>::iterator it = m_table.begin(); 
-	while(it != m_table.end()) {
-		time_t timestamp = it->second;
-		if (currentTime - timestamp > m_checkPeriod) {
-			it = m_table.erase(it);
-		}
-		else
-			++it;
-	}
+bool
+SyncInterestTable::insert(string interest)
+{
+  recursive_mutex::scoped_lock lock (m_mutex);
+  TableContainer::iterator it = m_table.find (interest);
+  if (it != m_table.end())
+    m_table.erase(it);
+  time_t currentTime = time(0);
+  m_table.insert (make_pair(interest, currentTime));
 }
 
-void SyncInterestTable::periodicCheck() {
-	sleep(4);
-	expireInterests();
+void SyncInterestTable::expireInterests()
+{
+  recursive_mutex::scoped_lock lock (m_mutex);
+  time_t currentTime = time(0);
+  TableContainer::iterator it = m_table.begin (); 
+  while (it != m_table.end())
+    {
+    time_t timestamp = it->second;
+    if (currentTime - timestamp > m_checkPeriod) {
+      it = m_table.erase(it);
+    }
+    else
+      ++it;
+  }
+}
+
+void SyncInterestTable::periodicCheck ()
+{
+  while (m_running)
+    {
+      try
+        {
+          // cout << "enterSleep: " << this_thread::get_id () << endl;
+      
+          this_thread::sleep (posix_time::seconds(4));
+          expireInterests ();
+        }
+      catch (boost::thread_interrupted e)
+        {
+          // should I just assign m_running = false here?
+          
+          // cout << "interrupted: " << this_thread::get_id () << endl;
+          // do nothing
+        }
+    }
 }
 
 }
diff --git a/model/sync-interest-table.h b/model/sync-interest-table.h
index f850708..bc5f2c2 100644
--- a/model/sync-interest-table.h
+++ b/model/sync-interest-table.h
@@ -30,11 +30,6 @@
 #include <boost/thread/thread.hpp>
 #include <ctime>
 
-/**
- * \defgroup sync SYNC protocol
- *
- * Implementation of SYNC protocol
- */
 namespace Sync {
 
 /**
@@ -46,32 +41,38 @@
 class SyncInterestTable
 {
 public:
-	SyncInterestTable();
+  SyncInterestTable ();
+  ~SyncInterestTable ();
 
-	/**
-	 * @brief Insert an interest, if interest already exists, update the
-	 * timestamp
-	 */
-	bool insert(std::string interest);
+  /**
+   * @brief Insert an interest, if interest already exists, update the
+   * timestamp
+   */
+  bool insert (std::string interest);
 
-	/**
-	 * @brief fetch all Interests and clear the table
-	 */
-	std::vector<std::string> fetchAll();
+  /**
+   * @brief fetch all Interests and clear the table
+   */
+  std::vector<std::string>
+  fetchAll ();
 
 private:
-	/**
-	 * @brief periodically called to expire Interest
-	 */
-	void expireInterests();
+  /**
+   * @brief periodically called to expire Interest
+   */
+  void expireInterests ();
 
-	void periodicCheck();
+  void periodicCheck ();
 
 private:
-	static const int m_checkPeriod = 4;
-	boost::unordered_map<std::string, time_t> m_table; // pit entries
-	boost::thread m_thread; // thread to check every 4 sec
-	boost::recursive_mutex m_mutex;
+  typedef boost::unordered_map<std::string, time_t> TableContainer;
+  
+  static const int m_checkPeriod = 4;
+  TableContainer m_table; // pit entries
+  
+  boost::thread m_thread; // thread to check every 4 sec
+  volatile bool m_running;
+  boost::recursive_mutex m_mutex;
 
 };