Howdy,
  we've discovered that windows seems to not allow suspended threads to
acquire synchronization objects, which make really really good sense,
while wine does. I've attached a simple test case, the code for the test
case and a ReWind licensed patch for the problem. Would people have a
look at the patch and let me know if it's the best way to fix it, or if
I've missed anything? (other than the attachements on the first go at this)?


Thanks,
Peter
[EMAIL PROTECTED]

<<attachment: TestSuspendThread.exe>>

// TestSuspendThread.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"
#include "windows.h"

CRITICAL_SECTION CritSect;

DWORD WINAPI TheyCallMeMrThread(
  LPVOID lpParameter
)
{
	printf("Thread   >B<   Attempting to get critical section! \n");
	EnterCriticalSection(&CritSect);
	printf("Thread   >B<   Critical section obtained!\n");
	printf("Thread   >B<    DONE\n");
	LeaveCriticalSection(&CritSect);
	return 0;
}


int main(int argc, char* argv[])
{
	HANDLE ThreadB;

	InitializeCriticalSection(&CritSect);
	printf("THREAD *A*: Gets Critical Section\n");
	EnterCriticalSection(&CritSect);

	ThreadB = CreateThread(
	  NULL,
	  0,
	  TheyCallMeMrThread,
	  NULL,
	  0,
	  NULL
	);

	printf("THREAD *A* WAITING FOR 2 seconds\n");
	Sleep(2000);

	printf("THREAD *A*: Suspending Thread B (while its still waiting for the critsect\n");
	SuspendThread(ThreadB);
	printf("THREAD *A*: Leaving Critical Section\n");
	LeaveCriticalSection(&CritSect);

	printf("THREAD *A* Waiting for 1 seconds...\n");
	Sleep(1000);
	printf("Thread *A* going to try to re-aquire critsect\n");
	EnterCriticalSection(&CritSect);

	printf("THREAD *A*: AQUIRED AGIAN, DONE..\n");
	Sleep(1000);
	LeaveCriticalSection(&CritSect);

	printf("THREAD *A*: Unsuspending ThreadB\n" );
	ResumeThread( ThreadB );

    WaitForSingleObject( ThreadB, INFINITE );

	printf("THREAD *A* detected threadB is finished\n" );

	return 0;
}

Index: server/thread.c
===================================================================
RCS file: /home/wine/wine/server/thread.c,v
retrieving revision 1.87
diff -u -r1.87 thread.c
--- server/thread.c     1 Feb 2003 01:38:40 -0000       1.87
+++ server/thread.c     13 Feb 2003 21:59:25 -0000
@@ -401,6 +401,9 @@
     struct thread_wait *wait = thread->wait;
     struct wait_queue_entry *entry = wait->queues;
 
+    /* Suspended threads may not acquire locks */
+    if( thread->suspend > 0 ) return -1;
+
     assert( wait );
     if (wait->flags & SELECT_ALL)
     {
@@ -938,7 +941,10 @@
     if ((thread = get_thread_from_handle( req->handle, THREAD_SUSPEND_RESUME )))
     {
         if (thread->state == TERMINATED) set_error( STATUS_ACCESS_DENIED );
-        else reply->count = resume_thread( thread );
+        else {
+          reply->count = resume_thread( thread );
+          if( reply->count == 1 ) wake_thread( thread );
+        }
         release_object( thread );
     }
 }

Reply via email to