public MultithreadedGame() : base() { ThreadGroup = new ThreadGroup(1, 5, comThreadingModel: ApartmentState.MTA) { NewThreadBusyThresholdMs = 2.0f }; #if SDL2 // Disable threading -flibit // Again, I say: NOPE. -flibit UseThreadedDraw = false; #else UseThreadedDraw = true; if (Thread.CurrentThread.GetApartmentState() != ApartmentState.STA) { throw new InvalidOperationException( "An STA apartment is required. See comments for more information." ); // Okay, so. // COM interop in .NET is a nightmare and doesn't work correctly in the presence of STA apartments and threads. // Because XNA Song shells out to Windows Media Player, and Windows Media Player is total garbage, // playing Songs in an MTA apartment tends to pretty reliably hang your game forever. // For now, UniformBinding bypasses COM wrappers, so things seem to work! But good luck. RIP. } #endif }
public GroupThread(ThreadGroup owner) { Owner = owner; WakeEvent = new ManualResetEventSlim(true); Thread = new Thread(ThreadMain); Thread.Name = string.Format("ThreadGroup {0} worker #{1}", owner.GetHashCode(), owner.Count); Thread.IsBackground = owner.CreateBackgroundThreads; if (owner.COMThreadingModel != ApartmentState.Unknown) Thread.SetApartmentState(owner.COMThreadingModel); owner.RegisterQueuesForNewThread(this); Thread.Start(this); }
protected ThreadServant(ThreadManager manager, Process process) { this.manager = manager; this.process = process; this.id = manager.NextThreadID; tgroup = process.Session.CreateThreadGroup ("@" + ID); tgroup.AddThread (ID); thread = process.Debugger.CreateThread (this, ID); }
public _Thread_140(JobContext job, TeraInputFormat inFormat, IList <InputSplit> splits , int sampleStep, int idx, TeraInputFormat.TextSampler sampler, long recordsPerSample , ThreadGroup baseArg1, string baseArg2) : base(baseArg1, baseArg2) { this.job = job; this.inFormat = inFormat; this.splits = splits; this.sampleStep = sampleStep; this.idx = idx; this.sampler = sampler; this.recordsPerSample = recordsPerSample; { this.SetDaemon(true); } }
/// <summary> /// Constructs a render coordinator. /// </summary> /// <param name="manager">The render manager responsible for creating frames and dispatching them to the graphics device.</param> /// <param name="synchronousBeginDraw">The function responsible for synchronously beginning a rendering operation. This will be invoked on the rendering thread.</param> /// <param name="synchronousEndDraw">The function responsible for synchronously ending a rendering operation and presenting it to the screen. This will be invoked on the rendering thread.</param> public RenderCoordinator( RenderManager manager, Func <bool> synchronousBeginDraw, Action synchronousEndDraw ) { Manager = manager; ThreadGroup = manager.ThreadGroup; UseResourceLock = manager.UseResourceLock; CreateResourceLock = manager.CreateResourceLock; _SyncBeginDraw = synchronousBeginDraw; _SyncEndDraw = synchronousEndDraw; DrawQueue = ThreadGroup.GetQueueForType <DrawTask>(); CoreInitialize(); }
public static void RemoveThreadGroup(ThreadGroup threadGroup, Type type = null, int groupId = -1) { if (type != null) { if (groupId >= 0) { var dico = m_ThreadGroups[type]; dico[groupId].Dispose(); dico.Remove(groupId); if (dico.Count == 0) { m_ThreadGroups.Remove(type); } } } }
public RenderManager(GraphicsDevice device, Thread mainThread, ThreadGroup threadGroup) { if (mainThread == null) { throw new ArgumentNullException("mainThread"); } MainThread = mainThread; DeviceManager = new DeviceManager(device); ThreadGroup = threadGroup; PrepareManager = new PrepareManager(ThreadGroup); _BufferGenerators = new ThreadLocal <Dictionary <Type, IBufferGenerator> >( MakeThreadBufferGeneratorTable ); _Frame = new Frame(); }
private static ThreadGroup StartCPU(DataType type, HeadsetModel headset, ElectrodePattern pattern, ElectrodeLayout layout, string path) { // declare colour matrix and electrodes (if needed) var matrix = new Color[headset.GetWidth(), headset.GetHeight()]; var electrodes = type == DataType.Phosphene ? pattern.GetElectrodePositions(layout) : default; // setup threadGroup var threadGroup = new ThreadGroup(); threadGroup.OnAllThreadsFinished += () => { EditorCallback.InvokeOnMainThread(() => { var asset = headset.CreateTexture(); asset.SetPixels(matrix.Flatten(false, true, true)); asset.Apply(); SaveAsset(asset, path); }); }; // generate the texture asynchronously threadGroup.ProcessArray(headset.GetWidth(), (i) => { var n = headset.GetHeight(); for (int j = 0; j < n; j++) { switch (type) { case DataType.Phosphene: matrix[i, j] = PhospheneMatrix.CalculatePoint(i, j, headset, electrodes).ToColour(); matrix[i, j] = AddRandomSeeds(matrix[i, j]); break; case DataType.Axon: matrix[i, j] = AxonMatrix.CalculatePoint(i, j, headset).Colour; break; } } }); // provide caller with threadGroup for completion statistics return(threadGroup); }
public void AutoSpawnMoreThreads() { using (var group = new ThreadGroup(0, 2)) { var queue = group.GetQueueForType<SleepyWorkItem>(); queue.Enqueue(new SleepyWorkItem()); group.NotifyQueuesChanged(); Assert.GreaterOrEqual(1, group.Count); queue.Enqueue(new SleepyWorkItem()); group.NotifyQueuesChanged(); var marker = queue.Mark(); Assert.GreaterOrEqual(2, group.Count); marker.Wait(); } }
public HandlerItem[] GetResultsFor(string search) { ThreadGroup searchGroup = new ThreadGroup(); List<HandlerItem> ret = new List<HandlerItem>(); foreach (GenericHandler handlerx in handlers) { GenericHandler handler = handlerx; searchGroup.AddAndRun(delegate() { HandlerItem[] tmp = handler.GetResultsFor(search); if (tmp == null) return; lock (ret) { ret.AddRange(tmp); } }); } searchGroup.WaitForCompletion(); return ret.ToArray(); }
/// <summary> /// Get the group of a specific class /// </summary> /// <typeparam name="T">The class</typeparam> /// <param name="groupId">The group id (default is 0)</param> /// <param name="existingGroup">If you created a group, you can use it here</param> /// <returns></returns> public static ThreadGroup GetThreadGroup <T>(int groupId = 0, ThreadGroup existingGroup = null) { var type = typeof(T); Dictionary <int, ThreadGroup> dicoGroups = null; ThreadGroup finalValue = null; if (!m_ThreadGroups.TryGetValue(type, out dicoGroups)) { dicoGroups = new Dictionary <int, ThreadGroup>(); m_ThreadGroups[type] = dicoGroups; } if (dicoGroups.TryGetValue(groupId, out finalValue)) { return(finalValue); } else { finalValue = existingGroup ?? new ThreadGroup(type, groupId); dicoGroups[groupId] = finalValue; return(finalValue); } }
public HandlerItem[] GetResultsFor(string search) { ThreadGroup searchGroup = new ThreadGroup(); List <HandlerItem> ret = new List <HandlerItem>(); foreach (GenericHandler handlerx in handlers) { GenericHandler handler = handlerx; searchGroup.AddAndRun(delegate() { HandlerItem[] tmp = handler.GetResultsFor(search); if (tmp == null) { return; } lock (ret) { ret.AddRange(tmp); } }); } searchGroup.WaitForCompletion(); return(ret.ToArray()); }
public BenchmarkQuery(int threadId, string threadGroupName, int iteration, string engineName, string sql, ThreadGroup threadGroup) { this.threadId = threadId; this.threadGroupName = threadGroupName; this.iteration = iteration; this.engineName = engineName; this.sql = sql; this._threadGroup = threadGroup; this.success = false; this.clientFromPoolTimer = 0; this.clientToPoolTimer = 0; this.totalQueryTimer = 0; this.execCursorTimer = 0; this.readCursorTimer = 0; this.cursorNetworkAndDeserializationTimer = 0; this.cursortotalRowCount = 0; this.cursorRowCount = 0; this.cursorAttributeCount = 0; this.cursorColumnCount = 0; this.cursorSizeBreakdown = new Dictionary <string, long>(); }
public static void DumpThreadGroupInfo(ThreadGroup tg, PrintStream @out) { string parentName = tg.Parent == null ? null : tg.Parent.Name; // Dump thread group info. @out.println("---- GROUP:" + tg.Name + (!string.ReferenceEquals(parentName, null) ? " parent:" + parentName : "") + (tg.Daemon ? " daemon" : "") + (tg.Destroyed ? " destroyed" : "") + " ----"); // Dump info for each thread. Thread[] allThreads = new Thread[1000]; tg.enumerate(allThreads, false); foreach (Thread thread in allThreads) { if (thread == null) { break; } @out.println("\"" + thread.Name + "\"" + (thread.Daemon ? " daemon" : "") + " prio=" + thread.Priority + " tid=" + thread.Id + " " + thread.State.name().ToLower()); //JAVA TO C# CONVERTER WARNING: The .NET Type.FullName property will not always yield results identical to the Java Class.getName method: @out.println(" " + typeof(Thread.State).FullName + ": " + thread.State.name()); foreach (StackTraceElement element in thread.StackTrace) { @out.println("\tat " + element); } } }
public Thread(ThreadGroup group, Action runHandler, string threadName, long stackSize) : this(group, new RunnableImplementor(runHandler), threadName, stackSize) { }
public Thread(ThreadGroup group, Action runHandler) : this(group, new RunnableImplementor(runHandler)) { }
static NamedThreadFactory() { _group = new ThreadGroup("NamedThreadFactory"); }
protected void LoadForums(int threadGroupID) { string writeBuffer = ""; ThreadGroup threadGroup = new ThreadGroup(); using (ThreadDataContext tdc = new ThreadDataContext()) { threadGroup = (from tg in tdc.ThreadGroups where tg.ThreadGroupID == threadGroupID select tg).SingleOrDefault(); writeBuffer += "<div class='GridBorder'>" + "<table width='100%' cellpadding='5' class='grid'>" + "<tr>" + "<td colspan='4' align='center' class='GridText' style='text-align:left;font-size:small;'>" + "<table>" + "<tr>" + "<td><img src='../Support/AppHead.png' alt='' /></td>" + "<td><b>" + threadGroup.Name + "</b></td>" + "<tr>" + "</table>" + "</td>" + "</tr>" + "<tr>" + "<td class='GridColumns' width='55%'><b>Thread</b></td>" + "<td class='GridColumns' width='30%'><b>Last Post</b></td>" + "<td class='GridColumns' width='15%'><b>Posts</b></td>" + "</tr>"; List <ThreadCategory> threadCategoryList = new List <ThreadCategory>(); threadCategoryList = (from tc in tdc.ThreadCategories where tc.ThreadGroupID == threadGroup.ThreadGroupID orderby tc.Name select tc).ToList(); foreach (ThreadCategory tc in threadCategoryList) { int postCount = (from t in tdc.Threads where t.ThreadCategoryID == tc.ThreadCategoryID select t).Count(); Thread threadLastPost = (from t in tdc.Threads where t.ThreadCategoryID == tc.ThreadCategoryID orderby t.LastPostDate descending select t).Take(1).SingleOrDefault(); string lastPostDetails = string.Empty; if (threadLastPost != null) { lastPostDetails = "<a href='Thread.aspx?threadid=" + threadLastPost.ThreadID + "&page=1'>" + (threadLastPost.Title.Length > 25 ? threadLastPost.Title.Substring(0, 25) + "..." : threadLastPost.Title) + "</a>" + "<br>by: <a href='../UserProfile.aspx?username="******"'>" + threadLastPost.LastPostBy + "</a>"; } writeBuffer += "<tr>" + "<td class='GridRows'>" + "<table cellpadding='0' cellspacing='0'>" + "<tr>" + "<td><img src='../Support/folderyellow32.png' /> </td>" + "<td><a href='ThreadList.aspx?categoryid=" + tc.ThreadCategoryID.ToString() + "&page=1' style='font-size:small;'>" + tc.Name + "</a><br>" + tc.Description + "</td>" + "</tr>" + "</table>" + "</td>" + "<td class='GridRows'>" + lastPostDetails + "</td>" + "<td class='GridRows' style='text-align:center'>" + postCount.ToString() + "</td>" + "</tr>"; } writeBuffer += "</table></div><br>"; } litCategoryHeader.Text = threadGroup.Name; litCategory.Text = writeBuffer; }
public bool parentOf(ThreadGroup prm1) { return(default(bool)); }
public _Thread_335(DaemonClient dc, Socket s, ThreadGroup baseArg1, string baseArg2 ) : base(baseArg1, baseArg2) { this.dc = dc; this.s = s; }
public void SingleThreadPerformanceTest() { const int count = 500000; var timeProvider = Time.DefaultTimeProvider; using (var group = new ThreadGroup(1, 1)) { var queue = group.GetQueueForType<VoidWorkItem>(); queue.DefaultStepCount = 1024; var item = new VoidWorkItem(); var beforeEnqueue = timeProvider.Ticks; for (int i = 0; i < count; i++) queue.Enqueue(ref item); var afterEnqueue = timeProvider.Ticks; var beforeWait = timeProvider.Ticks; var marker = queue.Mark(); marker.Wait(); var afterWait = timeProvider.Ticks; Console.WriteLine( "Enqueue took {0:0000.00}ms, Wait took {1:0000.00}ms. Final thread count: {2}", TimeSpan.FromTicks(afterEnqueue - beforeEnqueue).TotalMilliseconds, TimeSpan.FromTicks(afterWait - beforeWait).TotalMilliseconds, group.Count ); } }
public void MinimumThreadCount() { using (var group = new ThreadGroup( minimumThreads: 2 )) { Assert.GreaterOrEqual(group.Count, 2); } }
private void __Initialize(object param) { Program.mainForm.Invoke(new MethodInvoker(Program.mainForm.StartRefresh)); handlers.Clear(); handlers.Add(new StartMenuHandler()); handlers.Add(new NCalcHandler()); handlers.Add(new DirectoryBrowserHandler()); handlers.Add(new GoogleHandler()); ThreadGroup initializerGroup = new ThreadGroup(); foreach (GenericHandler handler in handlers) { try { initializerGroup.AddAndRun(handler.Initialize, param); } catch { } } initializerGroup.WaitForCompletion(); Program.mainForm.Invoke(new MethodInvoker(Program.mainForm.EndRefresh)); }
protected override bool DoResolve(ScriptingContext context) { // set whole method in a try-catch block: if anything goes wrong, an invalid breakpoint // number is set and the semaphore is released. try { if (global) { if (local) { throw new ScriptingException( "Cannot use both -local and -global."); } if (Group != null) { throw new ScriptingException( "Cannot use both -group and -global."); } tgroup = ThreadGroup.Global; } else if (local) { if (Group != null) { throw new ScriptingException( "Cannot use both -group and -local."); } tgroup = context.Interpreter.GetThreadGroup(Group, false); } else if (Group != null) { tgroup = context.Interpreter.GetThreadGroup(Group, false); } else { tgroup = ThreadGroup.Global; } if (context.Interpreter.HasTarget) { context.CurrentProcess = context.Interpreter.GetProcess(p_index); context.CurrentThread = context.Interpreter.GetThread(t_index); Mono.Debugger.Thread thread = context.CurrentThread; if (!thread.IsStopped) { throw new Mono.Debugger.TargetException(TargetError.NotStopped); } Backtrace backtrace = thread.GetBacktrace(); StackFrame frame; if (f_index == -1) { frame = backtrace.CurrentFrame; } else { if (f_index >= backtrace.Count) { throw new ScriptingException( "No such frame: {0}", f_index); } frame = backtrace [f_index]; } context.CurrentFrame = frame; if (ExpressionParser.ParseLocation( thread, thread.CurrentFrame, Argument, out location)) { return(true); } } if (Argument.IndexOf(':') > 0) { return(true); } try { UInt32.Parse(Argument); return(true); } catch { } Expression expr = context.Interpreter.ExpressionParser.Parse(Argument); if (expr == null) { throw new ScriptingException("Cannot resolve expression `{0}'.", Argument); } if (expr is PointerExpression) { address = ((PointerExpression)expr).EvaluateAddress(context); return(true); } if (!context.Interpreter.HasTarget) { return(true); } MethodExpression mexpr; try { mexpr = expr.ResolveMethod(context, type); } catch { if (lazy) { return(true); } throw new ScriptingException("No such method: `{0}'.", Argument); } if (mexpr != null) { location = mexpr.EvaluateSource(context); } else { location = context.FindMethod(Argument); } if (lazy) { return(true); } if (location == null) { throw new ScriptingException("No such method: `{0}'.", Argument); } return(true); } catch { EmonicInterpreter.breakpointNumber = -1; EmonicInterpreter.breakpointSem.Release(); throw; } }
public Thread(ThreadGroup group, Action runHandler, string threadName, long stackSize) : this(group, new RunnableImplementor (runHandler), threadName, stackSize) { }
public Thread(ThreadGroup group, Action runHandler) : this(group, new RunnableImplementor (runHandler)) { }
public void ManuallyStep() { using (var group = new ThreadGroup(0, 0)) { var queue = group.GetQueueForType<TestWorkItem>(); var item = new TestWorkItem(); Assert.IsFalse(item.Ran); queue.Enqueue(item); bool exhausted; queue.Step(out exhausted, 1); Assert.IsTrue(exhausted); Assert.IsTrue(item.Ran); } }
private static RandomizedContext Create(ThreadGroup tg, Type suiteClass, RandomizedRunner runner) { lock (globalLock) { var context = new RandomizedContext(tg, suiteClass, runner); contexts.Add(tg, context); context.threadResources.Add(ThreadClass.Current(), new ThreadResources()); return context; } }
public void MultipleThreadPerformanceTest() { const int count = 500000; var timeProvider = Time.DefaultTimeProvider; using (var group = new ThreadGroup(1)) { var queue = group.GetQueueForType<VoidWorkItem>(); queue.DefaultStepCount = 1024; var item = new VoidWorkItem(); var beforeEnqueue = timeProvider.Ticks; for (int i = 0; i < count; i++) { queue.Enqueue(ref item); // Notify the group periodically that we've added new work items. // This ensures it spins up a reasonable number of threads. if ((i % 20000) == 0) group.NotifyQueuesChanged(); } var afterEnqueue = timeProvider.Ticks; var beforeWait = timeProvider.Ticks; var marker = queue.Mark(); marker.Wait(); var afterWait = timeProvider.Ticks; Console.WriteLine( "Enqueue took {0:0000.00}ms, Wait took {1:0000.00}ms. Final thread count: {2}", TimeSpan.FromTicks(afterEnqueue - beforeEnqueue).TotalMilliseconds, TimeSpan.FromTicks(afterWait - beforeWait).TotalMilliseconds, group.Count ); } }
/// <summary> /// Constructs a render coordinator. /// </summary> /// <param name="manager">The render manager responsible for creating frames and dispatching them to the graphics device.</param> /// <param name="synchronousBeginDraw">The function responsible for synchronously beginning a rendering operation. This will be invoked on the rendering thread.</param> /// <param name="synchronousEndDraw">The function responsible for synchronously ending a rendering operation and presenting it to the screen. This will be invoked on the rendering thread.</param> public RenderCoordinator( RenderManager manager, Func<bool> synchronousBeginDraw, Action synchronousEndDraw ) { Manager = manager; ThreadGroup = manager.ThreadGroup; UseResourceLock = manager.UseResourceLock; CreateResourceLock = manager.CreateResourceLock; _SyncBeginDraw = synchronousBeginDraw; _SyncEndDraw = synchronousEndDraw; DrawQueue = ThreadGroup.GetQueueForType<DrawTask>(); CoreInitialize(); }
public void WaitForMarker() { using (var group = new ThreadGroup(0, 0)) { var queue = group.GetQueueForType<TestWorkItem>(); var item = new TestWorkItem(); Assert.IsFalse(item.Ran); queue.Enqueue(item); var marker = queue.Mark(); Assert.IsFalse(item.Ran); System.Threading.ThreadPool.QueueUserWorkItem((_) => { System.Threading.Thread.Sleep(250); bool exhausted; queue.Step(out exhausted, 1); Assert.IsTrue(exhausted); }); marker.Wait(); Assert.IsTrue(item.Ran); } }
/// <summary> /// Constructs a render coordinator. A render manager and synchronous draw methods are automatically provided for you. /// </summary> /// <param name="deviceService"></param> public RenderCoordinator(IGraphicsDeviceService deviceService, Thread mainThread, ThreadGroup threadGroup) { ThreadGroup = threadGroup; Manager = new RenderManager(deviceService.GraphicsDevice, mainThread, ThreadGroup); _SyncBeginDraw = DefaultBeginDraw; _SyncEndDraw = DefaultEndDraw; DrawQueue = ThreadGroup.GetQueueForType<DrawTask>(); CoreInitialize(); }
public void AutoSpawnThread() { using (var group = new ThreadGroup(0, 1)) { var queue = group.GetQueueForType<TestWorkItem>(); var item = new TestWorkItem(); Assert.IsFalse(item.Ran); queue.Enqueue(item); var marker = queue.Mark(); Assert.AreEqual(0, group.Count); Assert.IsFalse(item.Ran); group.NotifyQueuesChanged(); Assert.AreEqual(1, group.Count); marker.Wait(); Assert.IsTrue(item.Ran); } }
public ThreadGroup(ThreadGroup prm1, String prm2) { }
private RandomizedContext(ThreadGroup group, Type suiteClass, RandomizedRunner runner) { this.threadGroup = group; this.suiteClass = suiteClass; this.runner = runner; }
public Thread(ThreadGroup prm1, Runnable prm2, String prm3) { }
public Thread(ThreadGroup prm1, Runnable prm2) { }