fix deadlock [#1011342]

This PR fixes a deadlock issue with SyncNotification=true, massive notifications and normal queries. See bug  <http://pgfoundry.org/tracker/index.php?func=detail&aid=1011342&group_id=1000140&atid=590>, there is a testing source code as well.
The main fix is to replace IsNotificationThreadRunning by ShouldNotificationThreadStop. If ShouldNotificationThreadStop returns True, iteration loop in notification thread breaks and pending query in main thread can proceed. (Before this fix the iteration loop endlessly processed received notifications and hence pending query waited endlessly for Monitor.Enter(_socket)...)
The additional lock statements are necessary, because _notificationThreadStopCount is used in different threads. See <http://blogs.developpeur.org/jay/archive/2004/08/05/21876.aspx> for this problematic. (I guess, there are more of these issues in the code.)

Udo