-
Content Count
247 -
Joined
-
Last visited
-
Days Won
11
Everything posted by Primož Gabrijelčič
-
Recursive anonymous functions
Primož Gabrijelčič posted a topic in Algorithms, Data Structures and Class Design
Yes, they work 🙂 (and why wouldn't they?). program RecursiveAnon; {$APPTYPE CONSOLE} {$R *.res} uses System.SysUtils; function MakeFib: TFunc<integer,int64>; var fib: TFunc<integer,int64>; begin fib := function (value: integer): int64 begin if value < 3 then Result := 1 else Result := fib(value - 1) + fib(value -2); end; Result := fib; end; begin var fib := MakeFib; for var i := 1 to 10 do Write(fib(i), ' '); Readln; end. -
Short answer: Use Parallel.For. Long answer: Parallel.ForEach was written not for parallel processing of integers but for parallel processing of any weird kind of data. Because of that it is overly complex and not good for simple (for i in range) cases. It is usually about 10x slower than PPL's TParallel.For. That is why I later wrote Parallel.For, which works only on integer ranges and is on par with the PPL implementation.
-
ForEach runs only one "thread" at time
Primož Gabrijelčič replied to Tommi Prami's topic in OmniThreadLibrary
Use it's .OnStop function (async) or .OnStopInvoke (synchronized to the owner thread). -
ForEach runs only one "thread" at time
Primož Gabrijelčič replied to Tommi Prami's topic in OmniThreadLibrary
ExecuteAndWait processes messages in the worker thread. You have to process messages in the thread that owns the parallel task (in this case the main thread). -
ForEach runs only one "thread" at time
Primož Gabrijelčič replied to Tommi Prami's topic in OmniThreadLibrary
Although, hmmmm, I would expect Parallel.ForEach to work in blocking mode without any message processing. I will look into that as soon as possible. -
ForEach runs only one "thread" at time
Primož Gabrijelčič replied to Tommi Prami's topic in OmniThreadLibrary
Messages are still not processed while parallel for is executing. Run Parallel.ForEach.NoWait.Execute. Process messages while ForEach is running. -
ForEach runs only one "thread" at time
Primož Gabrijelčič replied to Tommi Prami's topic in OmniThreadLibrary
See: OmniThreadLibrary and console -
Calling Async from a thread causes an exception
Primož Gabrijelčič replied to andrey.b's topic in OmniThreadLibrary
Yes, it fails because the owner (anonymous thread) is destroyed before the worker (Parallel.Async). You could also run into problems because the owner thread is not processing Windows messages, which is a requirement for threads that own OTL tasks. Not in this simple example, but as soon as you start sending messages towards the owner or using OnTerminate handlers you would run into trouble.- 6 replies
-
- async
- createanonymousthread
-
(and 2 more)
Tagged with:
-
Calling Async from a thread causes an exception
Primož Gabrijelčič replied to andrey.b's topic in OmniThreadLibrary
For starters - why are you running Async from a background thread and not from the main thread?- 6 replies
-
- async
- createanonymousthread
-
(and 2 more)
Tagged with:
-
Looking forward to Delphi 12 Athens support
Primož Gabrijelčič replied to RCrandall's topic in OmniThreadLibrary
Official Delphi 12-supporting release: https://github.com/gabr42/OmniThreadLibrary/releases/tag/release-3.07.10 It should also appear in GetIt in a day or two. -
Looking forward to Delphi 12 Athens support
Primož Gabrijelčič replied to RCrandall's topic in OmniThreadLibrary
Although not officially released, OTL supports Delphi 12. Just download the latest version from the github and you're good to go. Official release will follow in two weeks. Primož -
Parallel.Pipeline & CreateProcess question
Primož Gabrijelčič replied to pushkin4219's topic in OmniThreadLibrary
I don't know. Show us the code. -
Use fController := CreateTask(TWorker.Create()).MsgWait.Run; Note the extra (). I don't know why, but compiler requires them.
-
Record as result for BackgroundWorker
Primož Gabrijelčič replied to chkaufmann's topic in OmniThreadLibrary
This should work just fine, I wrote a very similar code today and there were no problems: FWorker := Parallel.BackgroundWorker.NumTasks(1) .Execute( procedure (const workItem: IOmniWorkItem) var result: TTextBoxDetectorResults; begin var data := workItem.Data.ToRecord<TTextBoxDetectorData>; result := FAnalyzer_Asy.Analyze(data); workItem.Result := TOmniValue.FromRecord<TTextBoxDetectorResults>(result); end) .OnRequestDone_Asy( procedure (const Sender: IOmniBackgroundWorker; const workItem: IOmniWorkItem) begin var results := workItem.Result.ToRecord<TTextBoxDetectorResults>; OnAnalyzed_Asy(Self, workItem.UniqueID, results); end) You will have to put together a reproducible test case. -
Async/Await with updating visual controls
Primož Gabrijelčič replied to omnibrain's topic in OmniThreadLibrary
Yes, like that, but use TThread.Queue. There's no need to block the worker thread while memo is being updated. -
Hands-On Design Patterns with Delphi
Primož Gabrijelčič posted a topic in Tips / Blogs / Tutorials / Videos
Original post: https://www.thedelphigeek.com/2019/02/design-patterns-with-delphi-book.html Hurrah, hurray, my third book is here! It’s called Hands-On Design Patterns with Delphi and (just like my first book) I wrote it for Packt Publishing. (The second book was self-published and I expect the fourth one to be, too.) As the name says, “Design Patterns with Delphi” deals with design patterns. It is a bit different from most of design pattern books and websites you will find on the Internet. Case in point A: There are no UML diagrams. I don‘t speak UML. Tried to learn it few times but for some reason the whole concept doesn‘t agree with me. If you like diagrams, don’t fear though. Any book on design patterns - and most websites covering that topic - will gladly show how any design pattern can be diagrammed. That, however, is not important and should not govern your decision to buy the book. More important is case in point B: This book speaks Delphi. All the examples are written in Delphi and language features are used to the full. I also covered few less known Delphi idioms in separate sections. You’ll still be able to follow the discussion even though you may program in a different Pascal dialect. There’s also case in point 😄 Examples make sense. I deeply dislike classical design pattern examples of the “And then we want to write this program for different toolkits and it should also be able to draw circles, not only squares” kind. Euch! I tried to find a good example for each design pattern. Admittedly, I ended with few examples that draw triangles and squares on screen (mostly because some patterns were designed specifically for solving such problems), but most of them are of a more practical nature. This book covers all three classical design pattern categories - Creational patterns, Structural patterns, and Behavioral patterns. It also discusses patterns from the newer Concurrency patterns category. At the end I threw in some borderline-pattern(ish) topics and ended with a discussion of few patterns that cannot be strictly classified as “design” patterns. In this book you’ll find: Chapter 1 An introduction to patterns. Exploration of design principles, design patterns, and idioms. A mention of anti-patterns. A short description of most important design principles. Delphi idioms: creating and destroying objects. Chapter 2 Creation patterns part 1. Singleton. Dependency injection. Lazy initialization. Object pool. Chapter 3 Creation patterns part 2. Factory method, Abstract factory, Prototype, Builder. Delphi idioms: Assign and AssignTo. Chapter 4 Structural patterns part 1. Composite. Flyweight. Marker interface. Bridge. Delphi idioms: comparers and hashers. Chapter 5 Structure patterns part 2. Adapter. Proxy. Decorator. Facade. Delphi idioms: replacing components in runtime. Also: helpers. Chapter 6 Behavioral patterns part 1. Null object. Template method. Command. State. Chapter 7 Behavioral patterns part 2. Iterator. Visitor. Observer. Memento. Delphi idioms: for .. in. Chapter 8 Concurrency patterns part 1. Locking. Lock striping. Double-checked locking. Optimistic locking. Readers-writers lock. Delphi idioms: tasks and threads. Also: bitwise operators. Chapter 9 Concurrency patterns part 2. Thread pool. Messaging. Future. Pipeline. Chapter 10 Writing Delphi programs. Event-driven programming. Actions. LiveBindings. Form inheritance. Frames. Data modules. Chapter 11 Wrapping it up. Exceptions. Debugging. Functional programming. I hope you will like this book and learn a lot from it. I know I did during the nine months I spent writing it. And if you find any bug in the code, let me know so I can correct it in the second release! -
Hands-On Design Patterns with Delphi
Primož Gabrijelčič replied to Primož Gabrijelčič's topic in Tips / Blogs / Tutorials / Videos
The same goes for Packt. They sell books for $5 (action!) without asking. They even created a monstrosity which combines both my books together and they are selling it separately (again, without asking). But they did manage to make me more money than my self-published OmniThreadLibrary book, even though their commision is much higher than LeanPubs. So they do sell many books. -
Hands-On Design Patterns with Delphi
Primož Gabrijelčič replied to Primož Gabrijelčič's topic in Tips / Blogs / Tutorials / Videos
Mixed. They do their job, but you can definitely tell that it is an Indian team behind. Everything is "yes, of course" and then maybe something happens. Or maybe not. Plus they are very set in some formulaic ways - if you want to write a book, it has to fall into some already defined slot for which they know how they want organize it and then they insist on their way (how the content should be structured, what is allowed and what not etc). That is helpful, but also limiting and frustrating. Most of the time it works the best if you also say "yes, of course" and then do it in your own way. 🙂 Technical staff and editors are mediocre, at best. They definitely will not catch all errors. So - if you are looking for a perfect partner, they are not the one. If, however, you can just say "eh, whatever" from time to time and move on, they work just fine. They do pay on time, though. As for the other publishing houses, I have no idea. -
On general, no. In specific cases maybe yes.
-
Nope, the earliest supported version is 2007.
-
Indeed, I managed to screw that up 😞 Please take a fresh DSiWin32 from https://github.com/gabr42/OmniThreadLibrary/blob/master/src/DSiWin32.pas (just updated). It should fix the problem with D2007.
-
How to ADD CodeLibrarian snippets database?
Primož Gabrijelčič replied to PeterPanettone's topic in GExperts
No, I never did any work on CodeLibrarian (as far as I can remember). -
V3 works with VCL/command line/service. V4 *will* also support FMX (current development v4 version does not).
-
I'm only using Delphi tools for threading and synchronization so the end result should work on all supported platforms. I only tested on Ubuntu running on WSL2 though.
-
There is work being done (sporadically) in https://github.com/gabr42/OmniThreadLibrary/tree/v4-develop-2 Current status is: low-level tasks work on Linux, except when they don't and everything locks up hard. (And I have no idea yet why that happens.)