Goetz Sebastian MTA wrote:

> Hallo everyone,
> 
> First of all I have to mark myself as perl newbie so please be lenient
> towards me.
> 
> Now the facts:
> I am using perl 5.8.0 on a WinXP machine.
> I have increasing needs for some kind of mechanism that supplies me with
> extended thread functionality.
> Especially suspend and resume would be of great advantage.
> Unfortunately I found a CPAN module (Thread::Suspend) only capable for
> Lunix Systems.
> 
> Does anybody have an idea of how to get me out of this mess?

You could try using a shared vrbl to synchronize your threads or
possibly a mutex or semaphore would be easier.  Obviously this would
be a passive solution and your threads would have to be checking the
flags for changes rather than being actively suspended ffrom the
outside.  Take a look at the threads::shared module to see if that's
any help.

You could also try using Win32::API to call API suspend/resume functions.

Here are three functions that you could try playing with:


The GetCurrentThread function returns a pseudohandle for the current thread.
HANDLE GetCurrentThread(VOID)
Parameters
This function has no parameters.
Return Value
The return value is a pseudohandle for the current thread.
Remarks
A pseudohandle is a special constant that is interpreted as the current thread 
handle. The calling thread can use this handle to specify itself whenever a 
thread handle is required. Pseudohandles are not inherited by child processes.
This handle has the maximum possible access to the thread object. For systems 
that support security descriptors, this is the maximum access allowed by the 
security descriptor for the calling process. For systems that do not support 
security descriptors, this is THREAD_ALL_ACCESS.
The function cannot be used by one thread to create a handle that can be used 
by other threads to refer to the first thread. The handle is always interpreted 
as referring to the thread that is using it. A thread can create a "real" 
handle of itself that can be used by other threads, or inherited by other 
processes, by specifying the pseudohandle as the source handle in a call to the 
DuplicateHandle function.
The pseudohandle need not be closed when it is no longer needed. Calling the 
CloseHandle function with this handle has no effect. If the pseudohandle is 
duplicated by DuplicateHandle, the duplicate handle must be closed.
See Also
CloseHandle, DuplicateHandle, GetCurrentProcess, GetCurrentThreadId



The SuspendThread function suspends the specified thread.
DWORD SuspendThread(
      HANDLE  hThread   // handle to the thread
   );   
Parameters
hThread
Identifies the thread. The handle must have THREAD_SUSPEND_RESUME access.
Return Value
If the function succeeds, the return value is the thread's previous suspend 
count; otherwise, it is 0xFFFFFFFF. To get extended error information, use the 
GetLastError function.
Remarks
If the function succeeds, execution of the specified thread is suspended and 
the thread's suspend count is incremented.
Suspending a thread causes the thread to stop executing user-mode (application) 
code.
Each thread has a suspend count (with a maximum value of 
MAXIMUM_SUSPEND_COUNT). If the suspend count is greater than zero, the thread 
is suspended; otherwise, the thread is not suspended and is eligible for 
execution. Calling SuspendThread causes the target thread's suspend count to be 
incremented. Attempting to increment past the maximum suspend count causes an 
error without incrementing the count.
The ResumeThread function decrements the suspend count of a suspended thread.
See Also
ResumeThread



The ResumeThread function decrements a thread's suspend count. When the suspend 
count is decremented to zero, the execution of the thread is resumed.
DWORD ResumeThread(
    HANDLE  hThread     // identifies thread to restart
   );   
Parameters
hThread
Specifies a handle for the thread to be restarted. The handle must have 
THREAD_SUSPEND_RESUME access to the thread.
Return Value
If the function succeeds, the return value is the thread's previous suspend 
count.
If the function fails, the return value is 0xFFFFFFFF. To get extended error 
information, call GetLastError.
Remarks
The ResumeThread function checks the suspend count of the subject thread. If 
the suspend count is 0, the thread is not currently suspended. Otherwise, the 
subject thread's suspend count is decremented. If the resulting value is 0, 
then the execution of the subject thread is resumed.
If the return value is 0, the specified thread was not suspended. If the return 
value is 1, the specified thread was suspended but was restarted. If the return 
value is greater than 1, the specified thread is still suspended.
Note that while reporting debug events, all threads within the reporting 
process are frozen. Debuggers are expected to use the SuspendThread and 
ResumeThread functions to limit the set of threads that can execute within a 
process. By suspending all threads in a process except for the one reporting a 
debug event, it is possible to "single step" a single thread. The other threads 
are not released by a continue operation if they are suspended.
See Also
SuspendThread


-- 
  ,-/-  __      _  _         $Bill Luebkert    Mailto:[EMAIL PROTECTED]
 (_/   /  )    // //       DBE Collectibles    Mailto:[EMAIL PROTECTED]
  / ) /--<  o // //      Castle of Medieval Myth & Magic http://www.todbe.com/
-/-' /___/_<_</_</_    http://dbecoll.tripod.com/ (My Perl/Lakers stuff)
_______________________________________________
Perl-Win32-Users mailing list
Perl-Win32-Users@listserv.ActiveState.com
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs

Reply via email to