Example #1
0
/**
 *	使用 create_thread 创建的线程,线程过程必须自己显示的调用exit_thread,否则可能造成句柄泄漏
 */
void MThread::exit_thread(void)
{
#ifndef LINUXCODE
	_endthreadex(0);
#else
	pthread_exit(0);
#endif
}
Example #2
0
int
gl_thread_exit_func (void *retval)
{
  gl_thread_t thread = gl_thread_self ();
  thread->result = retval;
  _endthreadex (0); /* calls ExitThread (0) */
  abort ();
}
Example #3
0
void my_thread_exit(void *value_ptr)
{
#ifndef _WIN32
    pthread_exit(value_ptr);
#else
    _endthreadex(0);
#endif
}
Example #4
0
static unsigned __stdcall RunThread(void *arg)
{
    DebugLog << "RunThread" << std::endl;
    Thread *thread = (Thread *)arg;
    unsigned result = thread->Run();
    _endthreadex(0);
    return result;
}
Example #5
0
ResultType terminateDll(int aExitCode)
{
	g_script.Destroy();
	g_AllowInterruption = TRUE;
	hThread = NULL;
	_endthreadex( (DWORD)aExitCode );
	return (ResultType)aExitCode;
}
Example #6
0
void reloadDll()
{
	unsigned threadID;
	Line::sSourceFileCount = 0;
	g_script.Destroy();
	hThread = (HANDLE)_beginthreadex( NULL, 0, &runScript, &nameHinstanceP, 0, &threadID );
	_endthreadex( (DWORD)EARLY_RETURN ); 
}
void myFunc(void *param) {
   t *args = (t*) param;
   uint16_T *x = args->data1;
   uint16_T  *y = args->data2;
   printf("x=%d, y=%d\n", x, y);
   free(args);
   _endthreadex( 0 );
};
static unsigned __stdcall __CFWinThreadFunc(void *arg) {
    struct _args *args = (struct _args*)arg; 
    ((void (*)(void *))args->func)(args->arg);
    CloseHandle(args->handle);
    CFAllocatorDeallocate(kCFAllocatorSystemDefault, arg);
    _endthreadex(0);
    return 0; 
}
Example #9
0
// main function for the engine thread
unsigned __stdcall recogThreadMain( void *param )
{
	int ret;
	Recog *recog = (Recog *)param;
	ret = j_recognize_stream(recog);
	_endthreadex(ret);
	return(ret);
}
Example #10
0
void
ThreadExit(TThread * const threadP,
           int       const retValue) {

    threadP->threadDone(threadP->userHandle);

    _endthreadex(retValue);
}
Example #11
0
unsigned int __stdcall 
CNdasDDUService::_ServiceThreadProc(void* pArg)
{
	CNdasDDUService* pService = reinterpret_cast<CNdasDDUService*>(pArg);
	DWORD dwRet = pService->OnTaskStart();
	_endthreadex(dwRet);
	return dwRet;
}
Example #12
0
	void ExitThread(unsigned long dwExitCode)
	{
#ifndef _WIN32
		pthread_exit(&dwExitCode);
#else
		_endthreadex(dwExitCode);
#endif
	}
Example #13
0
unsigned __stdcall ray_render_thread(void *arg)
{
	int							slice_idx;
	ray_scene_thread_type		*thread;
	ray_scene_type				*scene;

		// get the thread and scene

	thread=(ray_scene_thread_type*)arg;
	scene=thread->parent_scene;

		// set some flags

	thread->shutdown_done=FALSE;

		// these are worker threads so
		// they suspend until needed

	while (TRUE) {

		SuspendThread(thread->thread);

			// in case spurious wake-up

		if (scene->thread_mode==ray_thread_mode_suspend) continue;

			// in shutdown?

		if (scene->thread_mode==ray_thread_mode_shutdown) {
			thread->shutdown_done=TRUE;
			_endthreadex(0);
			return(0);
		}

			// render the next slice

		while (TRUE) {
			slice_idx=-1;

			EnterCriticalSection(&scene->render.scene_lock);
			if (scene->render.next_slice_idx<ray_global.settings.slice_count) {
				slice_idx=scene->render.next_slice_idx;
				scene->render.next_slice_idx++;
			}
			LeaveCriticalSection(&scene->render.scene_lock);

			if (slice_idx==-1) break;

			ray_render_slice_run(scene,&scene->render.slices[slice_idx]);
		}

			// add up thread done count
			
		EnterCriticalSection(&scene->render.scene_lock);
		scene->render.thread_done_count++;
		LeaveCriticalSection(&scene->render.scene_lock);
	}
}
Example #14
0
  unsigned __stdcall envelopeDataThread( void *arg )
#endif /* Different threading models */
	{
	static const char *envData = "qwertyuiopasdfghjklzxcvbnm";
	BYTE fileBuffer[ BUFFER_SIZE ];
	const unsigned uThread = ( unsigned ) arg;
	const time_t startTime = time( NULL );
	int count, status;

	printf( "Thread %d started.\n", uThread );
	fflush( stdout );

	filenameFromTemplate( fileBuffer, CERT_FILE_TEMPLATE, 13 );

	for( count = 0; count < 150; count++ )
		{
		CRYPT_ENVELOPE cryptEnvelope;
		CRYPT_CERTIFICATE cryptCert;
		BYTE envBuffer[ BUFFER_SIZE ];
		int bytesCopied;

		/* Create the cert and envelope and add the cert to the envelope */
		status = importCertFile( &cryptCert, fileBuffer );
		if( cryptStatusOK( status ) )
			status = cryptCreateEnvelope( &cryptEnvelope, CRYPT_UNUSED,
										  CRYPT_FORMAT_CRYPTLIB );
		if( cryptStatusOK( status ) )
			status = cryptSetAttribute( cryptEnvelope,
										CRYPT_ENVINFO_PUBLICKEY, cryptCert );
		if( cryptStatusError( status ) )
			break;

		/* Envelope data and destroy the envelope */
		status = cryptPushData( cryptEnvelope, envData, strlen( envData ),
								&bytesCopied );
		if( cryptStatusOK( status ) )
			status = cryptPushData( cryptEnvelope, NULL, 0, NULL );
		if( cryptStatusOK( status ) )
			status = cryptPopData( cryptEnvelope, envBuffer, BUFFER_SIZE,
									&bytesCopied );
		if( cryptStatusOK( status ) )
			status = cryptDestroyEnvelope( cryptEnvelope );
		if( cryptStatusError( status ) )
			break;
		printf( "%c", uThread + '0' );
		}

	printf( "Thread %u exited after %d seconds.\n", uThread,
			time( NULL ) - startTime );
	fflush( stdout );
#ifdef UNIX_THREADS
	pthread_exit( NULL );
#else
	_endthreadex( 0 );
#endif /* Different threading models */
	return( 0 );
	}
Example #15
0
File: timeout.c Project: tasn/efl
unsigned int
_timeout(void *arg)
{
   int s = (int)(uintptr_t)arg;
   Sleep(s * 1000);
   _Exit(-1);
   _endthreadex(0);
   return 0;
}
Example #16
0
//退出一个线程,可以得到返回值
void ZCE_OS::pthread_exit(ZCE_THR_FUNC_RETURN thr_ret)
{
#if defined (ZCE_OS_WINDOWS)
    return _endthreadex(thr_ret);

#elif defined (ZCE_OS_LINUX)
    return ::pthread_exit (thr_ret);
#endif //#if defined (ZCE_OS_LINUX)
}
Example #17
0
UINT CALLBACK CFileMonitor::MonitorThread( VOID * aArgs )
{
    CFileMonitor * monitor = (CFileMonitor *)aArgs;
    while ( WAIT_IO_COMPLETION == WaitForSingleObjectEx( monitor->m_hEventStop , INFINITE  , TRUE ) );

    InterlockedDecrement( &monitor->m_uTotalThread );
    _endthreadex( TRUE );
    return TRUE;
}
Example #18
0
inline UINT __stdcall LuaNetworkThread::WorkerThread(void* context)
{
	LuaNetworkThread* thread = (LuaNetworkThread*)context;
	thread->ThreadRun();

	_endthreadex(0);

	return 0;
}
Example #19
0
unsigned int __stdcall 
CTask::
TaskThreadProcKickStart(void* lpParam)
#endif
{
	unsigned int retval = reinterpret_cast<CTask*>(lpParam)->OnTaskStart();
	_endthreadex(retval);
	return retval;
}
Example #20
0
UINT CALLBACK LogThread(void* param)
{
  TCHAR fileName[MAX_PATH];
  LogPath(fileName, _T("log"));
  while ( m_bLoggerRunning || (m_logQueue.size() > 0) ) 
  {
    if ( m_logQueue.size() > 0 ) 
    {
      SYSTEMTIME systemTime;
      GetLocalTime(&systemTime);
			WIN32_FILE_ATTRIBUTE_DATA fileInformation;

			GetFileAttributesEx(fileName, GetFileExInfoStandard, &fileInformation);

      if(logFileParsed != systemTime.wDay || fileInformation.nFileSizeLow > 10485760)
      {
        LogRotate();
        logFileParsed=systemTime.wDay;
        LogPath(fileName, _T("log"));
      }
      
      CAutoLock lock(&m_logFileLock);
      FILE* fp = _tfopen(fileName, _T("a+"));
      if (fp!=NULL)
      {
        SYSTEMTIME systemTime;
        GetLocalTime(&systemTime);
        wstring line = GetLogLine();
        while (!line.empty())
        {
          fwprintf_s(fp, L"%s", line.c_str());
          line = GetLogLine();
        }
        fclose(fp);
      }
      else //discard data
      {
        wstring line = GetLogLine();
        while (!line.empty())
        {
          line = GetLogLine();
        }
      }
    }
    if (m_bLoggerRunning)
    {
      m_EndLoggingEvent.Wait(1000); //Sleep for 1000ms, unless thread is ending
    }
    else
    {
      Sleep(1);
    }
  }
	_endthreadex(0);
  return 0;
}
Example #21
0
File: WDplot.c Project: bianle/daq
unsigned int __stdcall PlotThread(void* data)
{
	uint32_t retVal= 0;
	WDPlot_t *plotData= (WDPlot_t *)data;
	int i, s=0, ntr, comma=0, c, npts=0, WaitTime;
	FILE *fplot;

	SetPlotOptions(plotData);
	fplot = fopen(PLOT_DATA_FILE, "w");
	if (fplot == NULL) {
		retVal= -1;
		goto exitPoint;
	}
	ntr = plotData->NumTraces;
	while(ntr > 0) {
		fprintf(fplot, "%d\t", s);
		for(i=0; i<plotData->NumTraces; i++) {
			if (s < plotData->TraceSize[i]) {
				fprintf(fplot, "%d\t", plotData->TraceData[i][s]);
				npts++;
			}
			if (plotData->TraceSize[i] == (s-1))
				ntr--;
		}
		s++;
		fprintf(fplot, "\n");
	}
	fclose(fplot);

	/* str contains the plot command for gnuplot */
	fprintf(gnuplot, "plot ");
	c = 2; /* first column of data */
	for(i=0; i<plotData->NumTraces; i++) {
		if (comma)
			fprintf(gnuplot, ", ");
		fprintf(gnuplot, "'%s' using ($1*%f):($%d*%f) title 'ch%d' with lines %d", PLOT_DATA_FILE, plotData->Xscale, c++, plotData->Yscale, i, i+1);
		comma = 1;
	}
	fprintf(gnuplot, "\n"); 
	fflush(gnuplot);

	/* wait for gnuplot to finish */
	// TODO verificare documentazione gnuPlot per vedere se c'è modo di capire quando gnuPlot ha finito
	WaitTime = npts/100;
	if (WaitTime < 100)
		WaitTime = 100;
	Sleep(WaitTime);

exitPoint:
	// Free the traces storage
	for(i=0; i<plotData->NumTraces; i++)
		free( plotData->TraceData[i]);
	plotData->NumTraces= 0;
	_endthreadex( retVal );
    return retVal;
}
Example #22
0
 unsigned __stdcall getvectors_multi_threaded(float **Args){
#else
 void getvectors_multi_threaded(float **Args){
#endif

    /* Input image, output vectors */
    float *I, *V;
    float *K;
    /* Size of input image */
    int Isize[3];
    /* Size of input vectors */
    int Vsize[2];
    /* Size of vector volume */
    int image3D;
    /* Constants used */
    int kernelratio;
    int block[6];

    int ThreadID;
    int Nthreads;

    I=Args[0];
    Isize[0]=(int)Args[1][0];
    Isize[1]=(int)Args[1][1];
    Isize[2]=(int)Args[1][2];
    V=Args[2];
    Vsize[0]=(int)Args[3][0];
    Vsize[1]=(int)Args[3][1];
    Vsize[2]=(int)Args[3][2];
    kernelratio=(int)Args[4][0];
    image3D=(int)Args[4][1];
    block[0]=(int)Args[5][0];
    block[1]=(int)Args[5][1];
    block[2]=(int)Args[5][2];
    block[3]=(int)Args[5][3];
    block[4]=(int)Args[5][4];
    block[5]=(int)Args[5][5];
    K=Args[6];
    ThreadID=(int)Args[7][0];
    Nthreads=(int)Args[8][0];

    if(image3D==0) {
        get2Dvectors(I, Isize, V, Vsize, kernelratio, block, K, ThreadID, Nthreads);
    }
    else {
        get3Dvectors(I, Isize, V, Vsize, kernelratio, block, K, ThreadID, Nthreads);
    }

    /*  explicit end thread, helps to ensure proper recovery of resources allocated for the thread */
    #ifdef _WIN32
            _endthreadex( 0 );
    return 0;
    #else
            pthread_exit(NULL);
    #endif
}
Example #23
0
unsigned __stdcall gkThread::task(void* p)
{
	gkThread* pThread = static_cast<gkThread*>(p);

	pThread->run();

	_endthreadex(0);

	return 0;
}
Example #24
0
void tosThread_exit(void *exitCode)
{
#ifdef rt_LIB_Win32_i386
    HANDLE tHandle;
#endif

#ifdef tosThread_DEBUG
    if (exitCode == NULL)
        tosLog_debug("tosThread",
                     "exit",
                     "Terminating thread with exit code 0");
    else
        tosLog_debug("tosThread",
                     "exit",
                     "Terminating thread with exit code %d",
                     *(unsigned*)exitCode);
#endif

#ifdef rt_LIB_Win32_i386
    /*
     * Close thread handle, if exists
     */
    tHandle = GetCurrentThread();
    if (tHandle != (HANDLE)(-1L)) {
        CloseHandle(tHandle);
#ifdef tosThread_DEBUG
        tosLog_debug("tosThread",
                     "exit",
                     "Handle closed: %u, win32err=%d",
                     tHandle,
                     tosError_getCodeDetail());
#endif
    }

    if (exitCode == NULL)
        _endthreadex(0);
    else
        _endthreadex(*(DWORD*)exitCode);

#else
    pthread_exit(exitCode);
#endif
}
unsigned int __stdcall Win32Thread::threadFunc(void *args) {
    auto pThread = reinterpret_cast<Win32Thread*>(args);

    if (pThread) {
        pThread->Run();
    }

    _endthreadex(0);
    return 0;
}
Example #26
0
static unsigned __stdcall thread_proc(void* arg) {
	thread_params* proxy = (thread_params* )arg;
	proxy->func(proxy->arg);

	free(proxy);

	_endthreadex(0);

	return 0;
}
Example #27
0
unsigned int __stdcall CWinThread::RunThreadFunc( void* pParam )
{
	DWORD dwRet = RunThreadFuncNoCRT(pParam);

#ifndef _ATL_MIN_CRT
	_endthreadex(dwRet);
#endif//_ATL_MIN_CRT

	return DWORD(dwRet);
}
Example #28
0
static DWORD WINAPI Connect (LPTHREAD_ARG pThArg)
{
	BOOL f;
	/*	Pipe connection thread that allows the server worker thread 
		to poll the ShutDown flag. */
	f = ConnectNamedPipe (pThArg->hNamedPipe, NULL);
	_tprintf (_T("ConnNP finished: %d\n"), f);
	_endthreadex (0);
	return 0; 
}
Example #29
0
static DWORD
proc_stdin_thread(sub_process *pproc)
{
	DWORD in_done;
	for (;;) {
		if (WriteFile( (HANDLE) pproc->sv_stdin[0], pproc->inp, pproc->incnt,
					 &in_done, NULL) == FALSE)
			_endthreadex(0);
		// This if should never be true for anonymous pipes, but gives
		// us a chance to change I/O mechanisms later
		if (in_done < pproc->incnt) {
			pproc->incnt -= in_done;
			pproc->inp += in_done;
		} else {
			_endthreadex(0);
		}
	}
	return 0; // for compiler warnings only.. not reached
}
Example #30
0
// Naveen: v1. runscript() - runs the script in a separate thread compared to host application.
unsigned __stdcall runScript( void* pArguments )
{
	struct nameHinstance a =  *(struct nameHinstance *)pArguments;
	
	HINSTANCE hInstance = a.hInstanceP;
	LPTSTR fileName = a.name;
	OldWinMain(hInstance, 0, fileName, 0);	
	_endthreadex( (DWORD)EARLY_RETURN );  
    return 0;
}