Tuesday, January 31, 2012

OmniThreadLibrary Documentation–an Outline

That’s how it’s going to look. If you feel I have left something out, now is the time to raise your voice.

  1. Introduction
  2. Introduction to Multithreading
  3. Introduction to OmniThreadLibrary
    1. Tasks vs. Threads
    2. Locking (vs.) Messaging
    3. TOmniValue
  4. High-level multithreading
    1. Blocking Collection
    2. Async
    3. Future
    4. Join
    5. ParallelTask
    6. BackgroundWorker
    7. Pipeline
    8. ForEach
    9. ForkJoin
  5. Low-level multithreading
    1. Introduction
      1. Four ways to create a task
      2. Task Controller Needs an Owner
    2. Thread Pooling
      1. GOmniThreadPool
    3. Lock-free Collections
      1. Bounded Stack
      2. Bounded Queue
      3. Dynamic Queue
    4. Event Monitor
    5. Simple Tasks
      1. Name
      2. UniqueID
      3. Parameters
      4. Communication
        1. Comm
      5. Termination
        1. Terminate
        2. Terminated
        3. Stopped
        4. TerminateEvent
        5. WaitFor
      6. ExitCode
        1. SetExitStatus
      7. Exceptions
        1. FatalException
        2. DetachException
        3. SetException
      8. ChainTo
      9. Groups – Join/Leave
      10. MonitorWith
      11. Enforced
      12. Unobserved
      13. CancellationToken/CancelWith
      14. Lock/WithLock
      15. Counter/WithCounter
      16. ThreadData
      17. SetPriority
      18. WaitForInit
      19. SetQueueSize
    6. TOmniWorker Tasks
      1. Initialize, Run, Cleanup
      2. Timers
      3. Communication
        1. Sending to the Owner
        2. Receiving from the Owner
        3. Talking to other tasks
      4. Invoke
      5. Windows Message Processing
        1. Alertable
        2. MsgWait
      6. UserData
      7. RegisterWaitObject
    7. Task Group
  6. Synchronization
    1. IOmniCriticalSection
    2. Hassle-Free Critical Sections (TOmniCS)
    3. TOmniMREW
    4. Pessimistic, Optimistic and Busy-Wait Initialization
    5. Inverse Semaphore
    6. Cancellation Token
      1. GOmniCancellationToken
  7. Miscellaneous Stuff
    1. TOmniValue
      1. TOmniValueObj
    2. TOmniWaitableValue
    3. TOmniValueContainer
    4. TOmniCounter
    5. IOmniInterfaceDictionary
    6. TOmniRecordWrapper
    7. IOmniAutoDestroyObject
    8. Environment
    9. Hooks
    10. IOmniTaskControlList
    11. Atomic instructions (CAS, Move)
    12. Communication Observers
  8. How-to
    1. Web Download and Database Storage
    2. Background Worker and List Partitioning
    3. Background File Scanning
    4. Building a Connection Pool
    5. QuickSort
    6. Parallel Search in a Tree
    7. Multiple Workers with Multiple Frames

26 comments:

  1. A Glossary would be a great addition as well (IMO). e.g. Connection pool (is that database connections, thread connections, etc). For multi-threading newbs, they can then at least understand the "language".

    ReplyDelete
  2. That is a good idea but I don't know if my command of the English language is good enough to write something like that.

    ReplyDelete
    Replies
    1. Well, on your podcast with Jim McKeeth you had a noticeable accent that made understanding you difficult at times, but I've never had any trouble with your written English. You're pretty good at it, and I'm sure if the users come across something confusing, we can point it out and offer suggestions on how to improve the wording.

      Delete
    2. I am willing to help with the glossary. I'm a native english speaker and Delphi guy.

      Warren
      warren dot postma at the usual google mail stuff

      Delete
    3. Warren, great & thanks!

      Delete
  3. Anonymous09:35

    Don't worry, it's not as important to do some mistakes in your translations as it is in your code :-D
    Thank you again for this great piece of work !

    ReplyDelete
  4. With regards to the Glossary, it may even be worthwhile getting assistance by crowd-sourcing the Glossary. I'm sure that there is enough knowledgeable people in the community who could send in contributions to you and then you can add them or modify them to fit into the glossary. Just add the terms to the Glossary for those words that may be difficult to explain and let the Community contribute.
    Once again, gabr thanks for making your library so accessible to us all.

    ReplyDelete
  5. Anonymous10:56

    +1 for crowdsourcing. You could even make the documentation a wiki, a bit like Embarcadero's.

    Also, thanks for considering documentation at all, and planning it out to this level. It's great to see a project like this with great documentation.

    ReplyDelete
    Replies
    1. Anonymous12:03

      Yes, definitely consider wiki-ising it. People can add their own tips and tricks and even better code samples!

      I must say, I'm very eager to start reading it just from the outline... Documentation like this is the difference between an interesting project, and being adopted as mainstream, IMHO. It's rare to have such a well thought out point to point user guide with technical documentation.

      Fantastic work.

      Delete
  6. I'm sure you can find volunteers to clean up some of the English. I'd gladly offer my services on that front.

    ReplyDelete
  7. Anonymous11:52

    This looks great, I've been meaning to check out OmniThreadLibrary for some time, but just haven't had time to sit down and experiment with it. Structured documentation like this will definitely get me trying it out and hopefully using it effectively sooner, which makes it much more appealing :)

    ReplyDelete
  8. Anonymous12:05

    Most of your users won't need this, but under item 2 (Introduction to Multithreading), it would be great to add two subitems:
    a. Why multithread?
    b. When not to multithread
    Under item 3, add "Why use OmniThread?"

    ReplyDelete
  9. Thanks everybody for comments and contributions. I agree with all of them, especially crowdsourcing some parts.

    Indeed, documentation will definitely be available in a wiki format. I also intend to publish a free pdf and maybe a payable e-book variant.

    ReplyDelete
  10. One topic I haven't seen covered anywhere so far is using the OTL while dealing with COM/OLE objects. Or is that something you generally wouldn't recommend doing?

    ReplyDelete
  11. @Oliver, this is something I know nothing about. I would presume that it behaves exactly the same as the TThread does.

    ReplyDelete
  12. I assume you will also insert your usual "and for those using databases, good luck" comment :)

    I'm happy to contribute if you wiki-ise it, or proofreading etc if you want to email me a copy of anything. If you do do an ebook, please don't do it by converting the PDF, just point Calibre at the wiki.

    ReplyDelete
    Replies
    1. Anonymous11:41

      I'm using databases (dbExpress & MSSQL) with threading (not OmniThread). So far the only gotcha is that you must ensure there's a different connection object per thread.

      All I did is have a connection pool and GetConnection / FinishedWithConnection functions that ensure there's always a connection per thread ID. The connections are just reference counted to ensure they're not freed whilst in use.

      To be fair though, databases are only accessed to build a cache, so perhaps I'm not seeing some of the complexities?

      Delete
    2. Thanks for the info.

      Delete
    3. I have included your notes in the Wiki (http://otl.17slon.com/book/doku.php?id=book:howto:databases). If you don't agree with that (please check the conditions at http://otl.17slon.com/book/doku.php), send me an email or reply here and I'll remove your contribution.

      [I am pretty sure that you'll be OK with it but I want to play this fair and safe.]

      Delete
  13. Pfffff, databaseses :( While I know they are important, I'm just not competent in this area. I am still looking for a brave soul that knows about databases, needs multithreading and would pursue the quest to multithreaded database application. I would provide all support on the 'multithreading' part and add any missing parts to the OTL - and at the end blog about it, of course.

    Thanks for the offer, much appreciated. I'll keep you in mind.

    Don't worry, I would never do that. I will most probably write everything in the Word and synchronize it with a Wiki when I make any significant contribution. I know this sounds like a weird plan but I need a WYSIWYG environment to write efficiently - that's something I've found out a long time ago. I simply must see beautiful font on the screen or I'm all "bleuch why I'm spending my time on this crap".

    ReplyDelete
    Replies
    1. I think part of the reason for the paucity of documentation is that it's either very, very simple (one session or connection per thread. The end). Or it's very, very complex (ADO async, hand-rolled connection sharing, etc). If you get into NoSQL it becomes simple again, and in many ways I'd rather write sample code that does that.

      I'm happy to write up some commentary on databases once there's a spot for it and I can see the style of what you're writing. I've used OTL somewhat and databases rather a lot (and the combination whenever I've used OTL seriously).

      The simple approach is one connection per thread as noted above, and that's easy to do. But that can be wasteful of connections (which can lead to server thrashing), and if you're doing ye olde two tier development makes threading pretty much useless, since your database access is tied to the GUI which is tied to the main VCL thread.

      In that situation you can, however, cheat this quite significantly by opening datasets in threads but re-setting datasource.Active in the main thread when the dataset has finished opening (and changing the underlying session appropriately, of course). Mostly - this sort of trickery is undocumented and unsupported, but can give you huge performance wins with relatively small code changes (because you're opening slow queries in parallel). You can sometimes do this via ADO async mode but that has its own challenges.

      Delete
    2. Moz, thanks for the offer.

      If you scroll to the end of the chapter list at http://otl.17slon.com/book/doku.php, you'll see "OmniThreadLibrary and Databases". If you create a wiki account, I'll give you write access.

      Delete
    3. I have included your notes in the Wiki (http://otl.17slon.com/book/doku.php?id=book:howto:databases). If you don't agree with that (please check the conditions at http://otl.17slon.com/book/doku.php), send me an email or reply here and I'll remove your contribution.

      [I am pretty sure that you'll be OK with it but I want to play this fair and safe.]

      Delete
  14. Wiki: http://code.google.com/p/omnithreadlibrary/wiki/OtlBookContents

    I'll probably move the "OTL Book Wiki" somewhere else as the Google Code Wiki is quite clumsy.

    ReplyDelete
  15. "Final"(*) Wiki URL: http://otl.17slon.com/book/doku.php

    (*) May still change if there's a good reason.

    ReplyDelete
  16. It's what some of my friends were looking for to get some more deep use of OTL.
    Thanks!

    ReplyDelete