This is the mail archive of the
pthreads-win32@sources.redhat.com
mailing list for the pthreas-win32 project.
Implementation of pthread_kill() ...
- To: pthreads-win32 at sources dot redhat dot com
- Subject: Implementation of pthread_kill() ...
- From: Sylvain MARECHAL <sylvain dot marechal1 at libertysurf dot fr>
- Date: Fri, 23 Feb 2001 17:37:50 +0100
Did someone try to implement this.
Before doing it, I'm trying this little program, but it hangs :
Any idea ?
thank for reply
Sylvain
The program :
#include <windows.h>
#include <process.h>
#include <stdio.h>
///////////////////////////////////////////////////////////////////////////////
// Macros used to abstract the instruction pointer register for the various
// CPU platforms.
#if defined(_X86_)
#define PROGCTR(Context) (Context.Eip)
#endif
#if defined(_MIPS_)
#define PROGCTR(Context) (Context.Fir)
#endif
#if defined(_ALPHA_)
#define PROGCTR(Context) (Context.Fir)
#endif
#if defined(_PPC_)
#define PROGCTR(Context) (Context.Iar)
#endif
#if !defined(PROGCTR)
#error Module contains CPU-specific code; modify and recompile.
#endif
// The thread entry point
unsigned int WINAPI threadfunc( void * p)
{
int i = 0;
while(1)
{
printf( "Coucou from the thread (iteration %d)\n", i++ );
}
return 0;
}
// The signal function
static CONTEXT s_LastContext;
static void WINAPI SignalFunc(void)
{
// Calling the signal
// ...
// returning to last adresse
SetThreadContext( GetCurrentThread(), &s_LastContext);
}
void main()
{
HANDLE hThread;
DWORD IDThread;
int param = 0;
// Crete the thread
hThread = (HANDLE)_beginthreadex( NULL, 0, threadfunc, (void *)param,
0, (unsigned int *)&IDThread );
// Waiting the thread is running
Sleep(2000);
//
CONTEXT context;
// Stop the worker thread
SuspendThread(hThread);
if (WaitForSingleObject(hThread, 0) == WAIT_TIMEOUT)
{
// The worker has not yet terminated
// Get the worker thread's current CPU registers
context.ContextFlags = CONTEXT_CONTROL;
GetThreadContext(hThread, &context);
s_LastContext = context;
//memcpy( (void *)&s_LastContext, (void *)&context, sizeof(context) );
// Change the instruction pointer to our function
PROGCTR(context) = (DWORD) SignalFunc;
SetThreadContext(hThread, &context);
// Resuming the thread forces our function to be called
ResumeThread(hThread);
}
Sleep( INFINITE );
}