Ejemplo n.º 1
0
 void CreateLongRunningTask(XParameterizedThreadStart threadStartFunc)
 {
     _task = Task.Factory.StartNew(
         () =>
     {
         // We start the task running, then unleash it by signaling the readyToStart event.
         // This is needed to avoid thread reuse for tasks (see below)
         _readyToStart.WaitOne();
         // This is the first time we're using this thread, therefore the TLS slot must be empty
         if (_currentThread != null)
         {
             Debug.WriteLine("warning: currentThread already created; OS thread reused");
             Debug.Assert(false);
         }
         _currentThread = this;
         threadStartFunc(_startupParameter);
         _completed.Set();
     },
         CancellationToken.None,
         // .NET always creates a brand new thread for LongRunning tasks
         // This is not documented but unlikely to ever change:
         // https://github.com/dotnet/corefx/issues/2576#issuecomment-126693306
         TaskCreationOptions.LongRunning,
         TaskScheduler.Default);
 }
Ejemplo n.º 2
0
        protected SingleThreadEventExecutorOld(IEventExecutorGroup parent, string threadName, TimeSpan breakoutInterval, IQueue <IRunnable> taskQueue)
            : base(parent)
        {
            _firstTask     = true;
            _emptyEvent    = new ManualResetEventSlim(false, 1);
            _shutdownHooks = new HashSet <Action>();

            _loopAction     = Loop;
            _loopCoreAciton = LoopCore;

            _terminationCompletionSource = NewPromise();
            _taskQueue = taskQueue;
            _preciseBreakoutInterval = PreciseTimeSpan.FromTimeSpan(breakoutInterval);
            _scheduler = new ExecutorTaskScheduler(this);
            _thread    = new Thread(_loopAction);
            if (string.IsNullOrEmpty(threadName))
            {
                _thread.Name = DefaultWorkerThreadName;
            }
            else
            {
                _thread.Name = threadName;
            }
            _thread.Start();
        }
Ejemplo n.º 3
0
 public XThread(XParameterizedThreadStart threadStartFunc)
 {
     this.threadId   = GetNewThreadId();
     this.isExplicit = true;
     this.IsAlive    = false;
     this.CreateLongRunningTask(threadStartFunc);
 }
Ejemplo n.º 4
0
 public POPThread(XParameterizedThreadStart threadStartFunc)
 {
     this.completed    = new EventWaitHandle(false, EventResetMode.AutoReset);
     this.readyToStart = new EventWaitHandle(false, EventResetMode.AutoReset);
     this.threadId     = GetNewThreadId();
     this.IsAlive      = false;
     this.CreateLongRunningTask(threadStartFunc);
 }
Ejemplo n.º 5
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="start"></param>
 public XThread(XParameterizedThreadStart start)
     : this()
 {
     if (start == null)
     {
         throw new ArgumentNullException(nameof(start));
     }
     this.CreateLongRunningTask(start);
 }
Ejemplo n.º 6
0
 private void CreateLongRunningTask(XParameterizedThreadStart threadStartFunc)
 {
     this.task = Task.Factory.StartNew(delegate
     {
         this.readyToStart.WaitOne();
         currentThread = this;
         threadStartFunc(this.startupParameter);
         this.completed.Set();
     }, CancellationToken.None, TaskCreationOptions.LongRunning, TaskScheduler.Default);
 }
Ejemplo n.º 7
0
        protected SingleThreadEventExecutor(IEventExecutorGroup parent, string threadName, TimeSpan breakoutInterval, IQueue <IRunnable> taskQueue)
            : base(parent)
        {
            _loopAction     = Loop;
            _loopCoreAciton = LoopCore;

            _terminationCompletionSource = NewPromise();
            _taskQueue = taskQueue;
            _preciseBreakoutInterval = PreciseTimeSpan.FromTimeSpan(breakoutInterval);
            _scheduler = new ExecutorTaskScheduler(this);
            _thread    = new Thread(_loopAction);
            if (string.IsNullOrEmpty(threadName))
            {
                _thread.Name = DefaultWorkerThreadName;
            }
            else
            {
                _thread.Name = threadName;
            }
            _thread.Start();
        }
Ejemplo n.º 8
0
 void CreateLongRunningTask(XParameterizedThreadStart threadStartFunc)
 {
     this.task = Task.Factory.StartNew(() =>
     {
         // We start the task running, then unleash it by signaling the readyToStart event.
         // This is needed to avoid thread reuse for tasks (see below)
         this.readyToStart.WaitOne();
         // This is the first time we're using this thread, therefore the TLS slot must be empty
         if (tls_this_thread != null)
         {
             Debug.WriteLine("warning: tls_this_thread already created; OS thread reused");
             Debug.Assert(false);
         }
         tls_this_thread = this;
         threadStartFunc(this.startupParameter);
         this.completed.Set();
     },
                                       CancellationToken.None,
                                       TaskCreationOptions.LongRunning,
                                       TaskScheduler.Default);
 }