private void Remove(ThreadEntry entry) { Thread currentThread = Thread.CurrentThread; // Acquire lock. If you hit assert during acquire, and the code is handling // interrupt, you may need to use interrupt aware synchronization classes. // See the comment for InterruptAwareAutoResetEvent, InterruptAwareManualResetEvent, // and InterruptAwareMutex for details. bool shouldEnable = Processor.DisableInterrupts(); myLock.Acquire(currentThread); try { // Assert preconditions: entry should be on a either non signaled queue or if it is // on signaled queue thread's unblocked Id should be equal to entry's Id // We can run this assert only while spinlock is held because first we unblock thread // and then moving it from one queue to another. We do both of these operations while // holding spinlock. It is possible for thread to start running once it was unblocked. // When it reaches this method it is possible that it hasn't been moved to signaled queue yet // If that happens and we try to assert without holding spinlock assert will fire. VTable.Assert(entry.queue == this.waitingQueue || (entry.queue == this.signaledQueue && entry.Id == currentThread.UnblockedBy)); // Remove entry from the queue entry.RemoveFromQueue(); } finally { // Release lock myLock.Release(); // Reenable interrupts Processor.RestoreInterrupts(shouldEnable); } }
private async void ThreadInsertMethodAsync(object threadName) { try { for (int i = 0; i < Iterations; i++) { var name = threadName + " Test " + i; var entry = new ThreadEntry { Iteration = i, Name = name }; Collection.InsertOne(entry); IAsyncCursor <ThreadEntry> cursor = await Collection.FindAsync(Builders <ThreadEntry> .Filter.Eq("Name", entry.Name)); var result = await cursor.ToListAsync(); Assert.That(result.FirstOrDefault().Id, Is.EqualTo(entry.Id)); var deleteResult = await Collection.DeleteOneAsync(Builders <ThreadEntry> .Filter.Eq("Id", entry.Id)); Assert.That(deleteResult.DeletedCount, Is.EqualTo(1)); Thread.Sleep(Random.Next(MaxWait)); } } catch (Exception exception) { Console.Out.WriteLine("Ërror in Method2 Thread {0}", exception); Exceptions++; } finally { FinishedThread++; } }
public async Task <IActionResult> PutThreadEntry(int id, ThreadEntry threadEntry) { if (id != threadEntry.Id) { return(BadRequest()); } _context.Entry(threadEntry).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!ThreadEntryExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
public ThreadViewData(ThreadEntry ti, int cpuPeakCount) { this.Tid = ti.Tid; this.Priority = ti.Priority; this.Cpu = 0.0f; this.Name = ti.Name; this.cpuPeakCount = cpuPeakCount; }
private void openProcessTokenToolStripMenuItem_Click(object sender, EventArgs e) { if (listViewThreads.SelectedItems.Count > 0) { ThreadEntry thread = listViewThreads.SelectedItems[0].Tag as ThreadEntry; if (thread != null) { TokenForm.OpenForm(thread.Process.Token, true); } } }
/// <summary> /// Converts the string to an object. /// </summary> /// <param name="options">The options to use when converting.</param> /// <param name="text">The string to convert to an object.</param> /// <returns> /// The object created from the string. /// </returns> public override object ConvertFromString(TypeConverterOptions options, string text) { ThreadEntry threadEntry = _metricThreadEntries.Find( v => v.KeySimple.Trim().Equals(text.Trim(), StringComparison.InvariantCultureIgnoreCase)); if (threadEntry != null) { return(threadEntry); } return(text); }
public async Task <ActionResult <int> > PostThreadCreate(CreateThreadViewModel createThreadEntryViewModel) { ThreadEntry threadEntry = new ThreadEntry(); if (ModelState.IsValid) { string currentUserId = User.FindFirstValue(ClaimTypes.NameIdentifier); ApplicationUser currentUser = await _context.Users.FirstOrDefaultAsync(x => x.Id == currentUserId).ConfigureAwait(false); threadEntry.Author = currentUser; threadEntry.InjectFrom(createThreadEntryViewModel); threadEntry.CreatedAt = DateTime.Now; threadEntry.UpdatedAt = DateTime.Now; threadEntry.Locked = false; if (createThreadEntryViewModel.ForumId == -1) { threadEntry.PostNumber = 1; } else { threadEntry.Forum = await _context.Fora.FirstOrDefaultAsync(forum => forum.Id == createThreadEntryViewModel.ForumId); threadEntry.Parent = await _context.ForumThreadEntrys.Include(te => te.Root).Include(te => te.Children).FirstOrDefaultAsync(thread => thread.Id == createThreadEntryViewModel.parentId); threadEntry.Root = threadEntry.Parent.Root; } _context.ForumThreadEntrys.Add(threadEntry); try { await _context.SaveChangesAsync().ConfigureAwait(false); } catch (DbUpdateException exception) { Console.WriteLine($"SaveChangesAsync threw an exception Message: {exception.Message}"); } if (threadEntry.Parent == null && threadEntry.Root != null) { threadEntry.UpdatedAt = threadEntry.CreatedAt; threadEntry.Root.Id = threadEntry.Id; await _context.SaveChangesAsync().ConfigureAwait(false); } } return(threadEntry.PostNumber); }
private void MoveEntryToSignalQueue(ThreadEntry entry) { // Assert preconditions: Entry should be enqueued to nonsignaled queue protectiong // spinlock has to be taken VTable.Assert(waitingQueue.IsEnqueued(entry)); VTable.Assert(myLock.IsHeldBy(Thread.CurrentThread)); // Remove thread from waiting queue waitingQueue.Remove(entry); // Insert thread into signaled queue signaledQueue.EnqueueHead(entry); }
protected override bool AcquireOrEnqueue(ThreadEntry entry, int handleId) { bool didAcquire = true; // Assert preconditions: Current thread and entry's thread should be the same VTable.Assert(Thread.CurrentThread == entry.Thread); VTable.Assert(Thread.CurrentThread.IsAbortDelayed()); // If we currently don't own mutex try to acquire it or enqueue ourselves.. if (this.owner != entry.Thread) { didAcquire = base.AcquireOrEnqueue(entry, handleId); } return(didAcquire); }
private void DumpThread(ThreadEntry threadEntry) { using (NativeThread thread = threadEntry.Open(ThreadAcccessRights.GetContext | ThreadAcccessRights.SuspendResume | ThreadAcccessRights.QueryInformation)) { walker = new StackWalker(thread, memoryReader, resolver); try { thread.Suspend(); var stack = walker.Walk(); foreach (var frame in stack) { var fun = resolver.FindFunctionAtAddr((IntPtr)frame.returnAddress); Console.WriteLine($"{fun.name} {fun.virtualAddress-frame.returnAddress}"); } } finally { thread.Resume(); } } }
/// <summary> /// Starts new threads /// </summary> /// <param name="threadsCount">The number of threads to start</param> private void StartThreads(int threadsCount) { if (_isSuspended) { return; } lock (_workerThreads.SyncRoot) { // Don't start threads on shut down if (_shutdown) { return; } for (int i = 0; i < threadsCount; ++i) { // Don't create more threads then the upper limit if (_workerThreads.Count >= _stpStartInfo.MaxWorkerThreads) { return; } // Create a new thread Thread workerThread = new Thread(ProcessQueuedItems); // Configure the new thread and start it workerThread.IsBackground = _stpStartInfo.AreThreadsBackground; workerThread.Start(); ++_threadCounter; // Add it to the dictionary and update its creation time. _workerThreads[workerThread] = new ThreadEntry(this); _windowsPCs.SampleThreads(_workerThreads.Count, _inUseWorkerThreads); _localPCs.SampleThreads(_workerThreads.Count, _inUseWorkerThreads); } } }
private int WaitDone( ThreadEntry entry, int handleId, ref ThreadQueueStruct deferredQueue) { ThreadState state; int handledIdUnblocked; // Assert preconditions: We assume that queues are stable - spinlock is held when // this method is called VTable.Assert(myLock.IsHeldBy(Thread.CurrentThread)); // Indicate that thread migth be given owrneship of the object so that it can't be aborted entry.Thread.DelayStop(true); //Attempt to unblock thread, if we fail it means that thread has already timed out // If thread has timed out don't move it to signaled queue if ((handledIdUnblocked = entry.Thread.Unblock(handleId)) == handleId) { // The signal is good-we can take a thread from non-signaled queue and // move it to signaled MoveEntryToSignalQueue(entry); // If thread state is blocked - we will be responsible for waking it up if (entry.Thread.ShouldCallSchedulerUnBlock(handleId)) { // Enqueue entry onto deferred unblock queue. We will call unblock // once we are done with processing signal and we released the lock deferredQueue.EnqueueTail(entry.Thread.deferredEntry); } } else { // We haven't granted ownership to the thread so that we need to restore its // delay abort status entry.Thread.DelayStop(false); } return(handledIdUnblocked); }
protected virtual bool AcquireOrEnqueue(ThreadEntry entry, int handleId) { bool didAcquire = true; Thread currentThread = Thread.CurrentThread; // Acquire lock. If you hit assert during acquire, and the code is handling // interrupt, you may need to use interrupt aware synchronization classes. // See the comment for InterruptAwareAutoResetEvent, InterruptAwareManualResetEvent, // and InterruptAwareMutex for details. bool shouldEnable = Processor.DisableInterrupts(); myLock.Acquire(currentThread); try { // If the handle is signaled and thread hasn't been unblocked yet. if ((this.signaled == SignalState.Signaled) && (currentThread.Unblock(handleId) == handleId)) { // Make signaled state to be as dictated by child class during initialization this.signaled = this.signalStateAfterImediateWait; } else { // Enqueue entry into wating queue: this.waitingQueue.EnqueueHead(entry); // We couldn't acquire object set return value properly didAcquire = false; } } finally { // Release lock myLock.Release(); // Reenable interrupts Processor.RestoreInterrupts(shouldEnable); } return(didAcquire); }