Aquinus
Resident Wat-man
- Joined
- Jan 28, 2012
- Messages
- 13,174 (2.77/day)
- Location
- Concord, NH, USA
System Name | Apollo |
---|---|
Processor | Intel Core i9 9880H |
Motherboard | Some proprietary Apple thing. |
Memory | 64GB DDR4-2667 |
Video Card(s) | AMD Radeon Pro 5600M, 8GB HBM2 |
Storage | 1TB Apple NVMe, 4TB External |
Display(s) | Laptop @ 3072x1920 + 2x LG 5k Ultrafine TB3 displays |
Case | MacBook Pro (16", 2019) |
Audio Device(s) | AirPods Pro, Sennheiser HD 380s w/ FIIO Alpen 2, or Logitech 2.1 Speakers |
Power Supply | 96w Power Adapter |
Mouse | Logitech MX Master 3 |
Keyboard | Logitech G915, GL Clicky |
Software | MacOS 12.1 |
My point is that your example in #93 it's not showing that. Your building a string with the timing inside the new thread, before the thread has completed and really even before the output has even been printed to the screen. That's not measuring any time to get it to the outside world.Which is what the delegate and event are for. Any class listening to that event will get the data contained in the delegate. In this case, the delegate had the value (6) and the time (ticks). When the event is raised, the delegate method is called by the issuing thread and carried out (printed to console). In cases where cross-thread references are a problem, the issuing thread invokes the owning thread: owning thread executes the method while the issuing thread continues its tasks (usually requesting more work from the main thread).
I also get a perverse pleasure in seeing how much code it takes to implement this in other languages.
Code:
(require '[clojure.core.async :refer [<!! thread]])
(time (<!! (thread (+ 1 2 3))))
Last edited: