2using System.Collections.Generic;
5using System.Threading.Tasks;
18 Thread m_thread =
null;
20 AutoResetEvent m_evtDone =
new AutoResetEvent(
false);
21 ManualResetEvent m_evtRunning =
new ManualResetEvent(
false);
22 ManualResetEvent m_evtAbort =
new ManualResetEvent(
false);
23 bool m_bUseThread =
true;
28 public event EventHandler<ActionStateArgs<T>>
DoWork;
44 m_bUseThread = bUseThreadVsTask;
51 protected virtual void Dispose(
bool bDisposing)
53 if (m_evtCancel !=
null)
58 if (m_evtCancel !=
null)
94 m_thread.Start(
new ActionStateArgs<T>(cuda, log, m_evtCancel, nDeviceID, arg, nInitialDelay));
102 m_task = Task.Factory.StartNew(action,
new ActionStateArgs<T>(cuda, log, m_evtCancel, nDeviceID, arg), TaskCreationOptions.LongRunning);
107 private void waitForTerminate()
110 if (!m_evtDone.WaitOne(10000))
111 throw new Exception(
"The Internal Thread (thread) failed to stop!");
122 if (m_thread !=
null)
156 m_evtRunning.Reset();
168 if (m_evtAbort.WaitOne(0))
200 int m_nInitialDelay = 0;
217 m_evtCancel = evtCancel;
218 m_nDeviceID = nDeviceID;
220 m_nInitialDelay = nInitialDelay;
228 get {
return m_cuda; }
229 set { m_cuda = value; }
237 get {
return m_log; }
245 get {
return m_evtCancel; }
253 get {
return m_nDeviceID; }
261 get {
return m_arg; }
269 get {
return m_nInitialDelay; }
The CancelEvent provides an extension to the manual cancel event that allows for overriding the manua...
void Reset()
Resets the event clearing any signaled state.
virtual void Dispose(bool disposing)
Releases all resources used by the CancelEvent.
void Set()
Sets the event to the signaled state.
The Log class provides general output in text form.
The ActionStateArgs are sent to the DoWork event when fired from the InternalThreadEntry.
object Arg
Returns the user supplied argument.
Log log
Returns the Log used for output.
int InitialDelay
Returns the initial delay in ms (if any).
CudaDnn< T > cuda
Get/set the Cuda Dnn connection to Cuda.
ActionStateArgs(CudaDnn< T > cuda, Log log, CancelEvent evtCancel, int nDeviceID=0, object arg=null, int nInitialDelay=0)
The ActionStateArgs constructor.
int DeviceID
Returns the Device ID of the device to use in the thread.
The CudaDnn object is the main interface to the Low-Level Cuda C++ DLL.
The InternalThread manages an internal thread used for Parallel and data collection operations.
void StartInternalThread(CudaDnn< T > cuda, Log log, int nDeviceID=0, object arg=null, int nInitialDelay=0)
Starts running the internal thread function which then calls the DoWork event.
void InternalThreadEntry(object obj)
Specifies the internal thread entry.
void Dispose()
Releases all resources used by the InernalThread.
bool IsStarted
Returns whether or not the internal thread has been started.
EventHandler OnPreStop
The OnPreStop event fires just after signalling the thread to stop.
bool CancellationPending
Returns whether or not a cancellation is pending.
EventHandler< ActionStateArgs< T > > DoWork
The DoWork event is the working thread function.
virtual void Dispose(bool bDisposing)
Releases all resources used by the InernalThread.
void StopInternalThread()
Stops the internal thread.
EventHandler OnPreStart
The OnPreStart event fires just before starting the thread.
InternalThread(bool bUseThreadVsTask=false)
The InternalThread constructor.
The MyCaffe.basecode contains all generic types used throughout MyCaffe.
The MyCaffe.common namespace contains common MyCaffe classes.
The MyCaffe namespace contains the main body of MyCaffe code that closesly tracks the C++ Caffe open-...