Skip to content

Commit

Permalink
Remove compile time condition on Sleep() in ProcessServerMessages().
Browse files Browse the repository at this point in the history
  • Loading branch information
glenebob committed Oct 2, 2013
1 parent 9237cc1 commit b4169d7
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions src/Npgsql/NpgsqlConnector.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1066,13 +1066,13 @@ internal void ProcessServerMessages()
{
while (true)
{
#if ! WINDOWS
// Mono's implementation of System.Threading.Monitor does not appear to give threads
// priority on a first come/first serve basis, as does Microsoft's. As a result,
// under mono, this loop may execute many times even after another thread has attempted
// to lock on _socket. A short Sleep() seems to solve the problem effectively.
// to lock on _socket. A short Sleep() seems to solve the problem effectively.
// Note that Sleep(0) does not work.
Thread.Sleep(1);
#endif

lock (connector._socket)
{
// 20 millisecond timeout
Expand Down

1 comment on commit b4169d7

@roji
Copy link
Member

@roji roji commented on b4169d7 Oct 3, 2013

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi Glen.

The Thread.Sleep(1) is needed because the mono thread starvation problem, right? I agree it's bad to have compile-time checks of this kind (you don't know which DLL will run where), but why not make this a runtime check? http://www.mono-project.com/FAQ:_Technical, section "How can I detect if am running in Mono?"

Please sign in to comment.