Book recommendation for win32 multi-thread programming
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Page 1 of 2 12 LastLast
Results 1 to 15 of 19

Thread: Book recommendation for win32 multi-thread programming

  1. #1
    Join Date
    Dec 2010
    Posts
    593

    Book recommendation for win32 multi-thread programming

    Looking for a simple introductory level book on multi-threading,
    which covers mutex, semaphores etc.
    Nothing fancy, just plain simple and easy to understand.
    Thanks
    Jack

  2. #2
    Join Date
    Dec 2012
    Location
    England
    Posts
    2,327

    Re: Book recommendation for win32 multi-thread programming

    I would suggest Windows via c/c++ by Jeffrey Richter http://www.amazon.co.uk/Windows-Via-...effrey+richter

    This contains details re processes and threads and synchronisation etc.

    Note that previous versions of this book also cover the required material but can be obtained second hand significantly cheaper (eg http://www.amazon.co.uk/Programming-...effrey+richter)

    You might also want to consider Windows System Programming by Johnson Hart http://www.amazon.co.uk/Windows-Prog...EBCJHFV1G4PXE2
    Last edited by 2kaud; June 9th, 2014 at 05:17 AM.
    All advice is offered in good faith only. You are ultimately responsible for effects of your programs and the integrity of the machines they run on.

  3. #3
    Join Date
    Jul 2013
    Posts
    249

    Re: Book recommendation for win32 multi-thread programming

    Quote Originally Posted by lucky6969b View Post
    Looking for a simple introductory level book on multi-threading,
    which covers mutex, semaphores etc.
    Nothing fancy, just plain simple and easy to understand.
    Unless you really need the old stuff I suggest you you look forward and learn about C++ 11 concurrency insted. Even Microsoft recommends this.

    Sticking to C++ 11 will make your code portable but if you don't mind Microsoft also offers libraries beyond C++ 11 for certain common tasks like for example to easily replace a for loop with a parallel_for loop. It also offers concurrent versions of standard STL data structures. It's called PPL.

    Basically locks should be avoided (just like you avoid global data). They introduce dependencies and the code may not scale well. Lock-free concurrent code is what to aim for. By adopting this kind of thinking now you will be ahead later when everybody else is struggling to catch up eventually. It takes years to make the transition. It's like going from procedural to OO.

  4. #4
    Arjay's Avatar
    Arjay is offline Moderator / MS MVP Power Poster
    Join Date
    Aug 2004
    Posts
    11,236

    Re: Book recommendation for win32 multi-thread programming

    Agree with razzle on using C++ 11 and above, but if you are coding for Windows it would be good to get background on how the OS works with regard to processes and threads.

    One of the best books for this is Programing Applications for Microsoft Windows by Jeffrey Richter.

  5. #5
    Join Date
    Dec 2012
    Location
    England
    Posts
    2,327

    Re: Book recommendation for win32 multi-thread programming

    One of the best books for this is Programing Applications for Microsoft Windows by Jeffrey Richter.
    As per my post #2, this has been superseded by 'Windows via c/c++' by Jeffrey Richter.
    All advice is offered in good faith only. You are ultimately responsible for effects of your programs and the integrity of the machines they run on.

  6. #6
    Arjay's Avatar
    Arjay is offline Moderator / MS MVP Power Poster
    Join Date
    Aug 2004
    Posts
    11,236

    Re: Book recommendation for win32 multi-thread programming

    Quote Originally Posted by 2kaud View Post
    As per my post #2, this has been superseded by 'Windows via c/c++' by Jeffrey Richter.
    Okay, great.

  7. #7
    Join Date
    Dec 2012
    Location
    England
    Posts
    2,327

    Re: Book recommendation for win32 multi-thread programming

    Quote Originally Posted by Arjay View Post
    Okay, great.
    Richter has an 'annoying' habit of bringing out updated revisions to his books with completely different titles!

    In chronological descending order:
    Windows via c/c++
    Programming Applications for Windows
    Advanced Windows
    Advanced Win32 programming
    Advanced Windows NT

    Basically all of these above cover the same ground with additions for new facilities in the different versions of Windows and different emphasis (eg older versions cover DLL injection in more detail).

    There is also
    Server side applications for Windows 2000 (covers services, administration/management, security etc)
    Windows 95: A developers guide (covers windows WIN32 gui programming and is still relevant if you program using win32 api)
    All advice is offered in good faith only. You are ultimately responsible for effects of your programs and the integrity of the machines they run on.

  8. #8
    Arjay's Avatar
    Arjay is offline Moderator / MS MVP Power Poster
    Join Date
    Aug 2004
    Posts
    11,236

    Re: Book recommendation for win32 multi-thread programming

    Quote Originally Posted by 2kaud View Post
    Richter has an 'annoying' habit of bringing out updated revisions to his books with completely different titles!

    In chronological descending order:
    Windows via c/c++
    Programming Applications for Windows
    Advanced Windows
    Advanced Win32 programming
    Advanced Windows NT

    Basically all of these above cover the same ground with additions for new facilities in the different versions of Windows and different emphasis (eg older versions cover DLL injection in more detail).

    There is also
    Server side applications for Windows 2000 (covers services, administration/management, security etc)
    Windows 95: A developers guide (covers windows WIN32 gui programming and is still relevant if you program using win32 api)
    I suspected he might have had a new version over the one I recommended, but I wasn't sure (and didn't want to recommend the wrong book).

    The first book on the subject I read was Advanced Windows NT. I think it took me about a year to get through. Fortunately with each new title, they are easier to read. Sure, my understanding has increased, but also Mr. Richter has been improving his craft as well.

  9. #9
    Join Date
    Dec 2010
    Posts
    593

    Re: Book recommendation for win32 multi-thread programming

    Thanks, that's a lot to choose from....
    Actually, I've got a few sitting on my shelf and didn't have time to look at them.
    Let me check them out first....
    Jack

  10. #10
    Join Date
    Jun 2002
    Location
    Stockholm, Sweden
    Posts
    1,597

    Re: Book recommendation for win32 multi-thread programming

    Quote Originally Posted by razzle View Post
    Basically locks should be avoided (just like you avoid global data). They introduce dependencies and the code may not scale well. Lock-free concurrent code is what to aim for.
    Lock-free is the ideal, but hard to realize in practice. What you want is a solution that very rarely locks, and when it does, the locks are held for just a few instruction cycles. Also, you'd maybe like an API that memory wise allows locking with finer granularity.
    Nobody cares how it works as long as it works

  11. #11
    Join Date
    Jul 2013
    Posts
    249

    Re: Book recommendation for win32 multi-thread programming

    Quote Originally Posted by zerver View Post
    Lock-free is the ideal, but hard to realize in practice.
    That's right and that's why I also wrote "aim for" lock-free code.

    My point is that with the advent of multi-core processors focus has shifted from the approach the OP seems keen on learning (heavy-weight OS threads and (b)locking) to light-weight threading with Intel TBB as the archetypical example,

    https://www.threadingbuildingblocks.org/

    (and Microsoft offers the PPL library as I mentioned).

    Concurrency then becomes more of an upfront design issue rather than an afterthough where sequentially designed code must be forcefully squeezed into concurrent shoes. It's painful and seldom looks very good.

    So unless there's a very specific reason to learn about win32 multi-threading I think one has more to gain from learning C++ concurrency with focus on writing good, ideally lock-free, concurrent applications making full use of multicore hardware.

  12. #12
    Join Date
    Apr 2000
    Location
    Belgium (Europe)
    Posts
    3,831

    Re: Book recommendation for win32 multi-thread programming

    Quote Originally Posted by zerver View Post
    What you want is a solution that very rarely locks, and when it does, the locks are held for just a few instruction cycles. Also, you'd maybe like an API that memory wise allows locking with finer granularity.

    Lock free is not "ideal".
    It can offer an incredible advantage over similar implementation with locks because of the obvious non need for a lock. But it has issues of itself.
    - The need for a lock can have multiple blocking conditions, this cannot be achieved via a lock-free algorithm.
    - lock free algorithms don't respect priority through the lock.
    - used incorrectly you can starve your CPU of actual work from excessive spinning in the lock-free algorithm
    - lock free algorithms do not guarantee an upper boundary for execution. This makes them typically unsuitable for real-time problems, even though you'd expect them to be ideally suited for it because they have such a short lower bound, it's a common mistake made in RT software.
    - it is difficult or even impossible to proove or "guarantee" a lock free algorithm actually works as specified.

    Also, not all problems CAN be achieved via a lock-free algorithm, even if they only have one blocking condition.

    Typically speaking however, developing a lock free algorithm is not something a novice user should try to do, even experts break their legs over this.
    Using wellmade libraries/classes of lock free algo's is easy enough of course, just be sure you're getting what you bargained for.


    Quote Originally Posted by zerver View Post
    What you want is a solution that very rarely locks, and when it does, the locks are held for just a few instruction cycles.
    Not quite.
    You want a solution that only locks when needed.
    And only for so long as is needed.


    suggesting "to very rarely lock" is what makes people 'invent' convoluted schemes where they end up not locking when they should have.
    EVERY access (read or write) to a resource shared by 2 or more threads where one of the threads will be modifying the resource at some point in time needs synchronisation. The Obvious way to synchronise is locking, but there are alternative ways that may be beneficial.


    It doesn't matter at all how lock the lock is held (even minutes) if it is held only for as long as it needs to be.


    Quote Originally Posted by zerver View Post
    Also, you'd maybe like an API that memory wise allows locking with finer granularity.
    This may work or it may not work, finer granularity typically means more individual locks which has issues of it's own.

  13. #13
    Join Date
    Jun 2002
    Location
    Stockholm, Sweden
    Posts
    1,597

    Re: Book recommendation for win32 multi-thread programming

    Quote Originally Posted by OReubens View Post
    It doesn't matter at all how long the lock is held (even minutes) if it is held only for as long as it needs to be.
    Good points, but here I cannot agree. A lock held for a long time may indicate a design flaw. These typical producer/consumer scenarios where one of the parties cannot work because the other holds a lock. You should only lock during the actual read/write, fetch/post the necessary data and then unlock asap.

    It is usually preferred to lock several times with a shorter duration. However, due to the associated overhead that comes with each locking, you should never hunt for extremes. If you have a reasonable amount of reasonably sized items to insert into a container, it is better to lock just once and insert them all in one go.
    Nobody cares how it works as long as it works

  14. #14
    Join Date
    Apr 2000
    Location
    Belgium (Europe)
    Posts
    3,831

    Re: Book recommendation for win32 multi-thread programming

    Quote Originally Posted by zerver View Post
    Good points, but here I cannot agree. A lock held for a long time may indicate a design flaw. These typical producer/consumer scenarios where one of the parties cannot work because the other holds a lock. You should only lock during the actual read/write, fetch/post the necessary data and then unlock asap.
    Well then you agree "only hold the lock for as long as it needs to be"

    if it "needs to be" minutes, then that is an inherent design decision. This could indicate a flaw somewhere, but it might also be entirely intended (I've seen it done for 15-30 mins) when the app was running a maintenance on the internal data structures), the duration was entirely intended (and rare).

    Whether or not holding a lock for minutes is a design flaw is up to the designers to evaluate, maybe there is another way to do things that reduces the duration, but this may have a cost elsewhere. This is where the design needs to be tested with the expected/desired behaviour.


    Quote Originally Posted by zerver View Post
    It is usually preferred to lock several times with a shorter duration. However, due to the associated overhead that comes with each locking, you should never hunt for extremes. If you have a reasonable amount of reasonably sized items to insert into a container, it is better to lock just once and insert them all in one go.
    it's all about design decisions.
    if you have high priority producers and low priority consumers, then it may very well be advantageous to hold a lock for longer in the producer(s) to do more work.

    there are no hard rules here, (except for the EVERY access to a mutable shared resource needs synchronisation). Advocating a "go out of your way to reduce the duration of a lock" is not a good rule. GOOD multithreading is hard. it's simple to explain how synchronisation works and why it's needed, but applying it effectively in practice is anything but simple.

  15. #15
    Arjay's Avatar
    Arjay is offline Moderator / MS MVP Power Poster
    Join Date
    Aug 2004
    Posts
    11,236

    Re: Book recommendation for win32 multi-thread programming

    I wonder, how many of you folks doing multithreading use RAII with respect to locking?

Page 1 of 2 12 LastLast

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Azure Activities Information Page

Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center