Created
June 19, 2012 22:58
Revisions
-
bojanrajkovic revised this gist
Jun 19, 2012 . 1 changed file with 8 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,8 @@ bojanrajkovic@dynamic-033 ~/C/O/G/G/b/Debug $ mono --debug GCDTest.exe Hello, world. Is thread pool thread: False Dispatch queue: org.mono.tpl_dispatch_queue Hello, world from non-GCD task. Is thread pool thread: True Dispatch queue: com.apple.root.default-overcommit-priority -
bojanrajkovic revised this gist
Jun 19, 2012 . 1 changed file with 9 additions and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -19,12 +19,20 @@ public static void Main (string[] args) Console.WriteLine ("Is thread pool thread: {0}", Thread.CurrentThread.IsThreadPoolThread); Console.WriteLine ("Dispatch queue: {0}", DispatchQueue.CurrentQueue.Label); }).Wait (Timeout.Infinite); Console.WriteLine (); Task.Factory.StartNew (() => { Console.WriteLine ("Hello, world from non-GCD task."); Console.WriteLine ("Is thread pool thread: {0}", Thread.CurrentThread.IsThreadPoolThread); Console.WriteLine ("Dispatch queue: {0}", DispatchQueue.CurrentQueue.Label); }).Wait (Timeout.Infinite); } } public class GrandCentralDispatchTaskScheduler : TaskScheduler { static readonly DispatchQueue gcdDispatchQueue = new DispatchQueue ("org.mono.tpl_dispatch_queue"); protected override System.Collections.Generic.IEnumerable<Task> GetScheduledTasks () { -
bojanrajkovic revised this gist
Jun 19, 2012 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,4 +1,3 @@ using System; using System.Threading.Tasks; using MonoMac.CoreFoundation; @@ -18,6 +17,7 @@ public static void Main (string[] args) tf.StartNew (() => { Console.WriteLine ("Hello, world."); Console.WriteLine ("Is thread pool thread: {0}", Thread.CurrentThread.IsThreadPoolThread); Console.WriteLine ("Dispatch queue: {0}", DispatchQueue.CurrentQueue.Label); }).Wait (Timeout.Infinite); } } -
bojanrajkovic created this gist
Jun 19, 2012 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,55 @@ using System; using System.Threading.Tasks; using MonoMac.CoreFoundation; using MonoMac.AppKit; using System.Threading; namespace GCDTest { class MainClass { public static void Main (string[] args) { NSApplication.Init (); var gcds = new GrandCentralDispatchTaskScheduler (); var tf = new TaskFactory (gcds); tf.StartNew (() => { Console.WriteLine ("Hello, world."); Console.WriteLine ("Is thread pool thread: {0}", Thread.CurrentThread.IsThreadPoolThread); }).Wait (Timeout.Infinite); } } public class GrandCentralDispatchTaskScheduler : TaskScheduler { DispatchQueue gcdDispatchQueue = DispatchQueue.DefaultGlobalQueue; protected override System.Collections.Generic.IEnumerable<Task> GetScheduledTasks () { throw new NotImplementedException (); } protected override void QueueTask (Task task) { gcdDispatchQueue.DispatchAsync (delegate { TryExecuteTaskInline (task, false); }); } // TODO: Tasks cannot be dequeued. protected override bool TryDequeue (Task task) { return false; } protected override bool TryExecuteTaskInline (Task task, bool taskWasPreviouslyQueued) { if (taskWasPreviouslyQueued && !TryDequeue (task)) return false; return TryExecuteTask (task); } } }