thread synchronization

This is a discussion on thread synchronization within the Windows Programming forums, part of the Platform Specific Boards category; Hello.. Im working on an app where I have more different threads running at the same time, and using the ...

  1. #1
    l2u
    l2u is offline
    Registered User
    Join Date
    May 2006
    Posts
    630

    thread synchronization

    Hello..

    Im working on an app where I have more different threads running at the same time, and using the same class object. I use mutex only when each thread wants to write to the class, but I wonder if I would have to use it also when each thread wants to read/access objects in class?

    Thanks for help

  2. #2
    Yes, my avatar is stolen anonytmouse's Avatar
    Join Date
    Dec 2002
    Posts
    2,544
    It is fine for two threads to be reading the same object at the same time. However, if it is possible that one thread may be reading an object while another is writing to it, then you will need to use synchronization to prevent this.

    Therefore, typically, all read and write access will be synchronized, because it is often not worth the effort to optimize for the multi-read scenario (known as the readers/writers problem).

  3. #3
    Registered User
    Join Date
    Aug 2003
    Posts
    288
    I found a comparison of the different synchronization methods and an implementation of the fastest on MSDN if you're interested:
    http://msdn.microsoft.com/library/de...n_metrsect.asp

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. thread synchronization
    By radeberger in forum C++ Programming
    Replies: 13
    Last Post: 03-29-2009, 10:21 AM
  2. Thread Synchronization in Win32
    By passionate_guy in forum C Programming
    Replies: 0
    Last Post: 02-06-2006, 04:34 AM
  3. [code] Win32 Thread Object
    By Codeplug in forum Windows Programming
    Replies: 0
    Last Post: 06-03-2005, 03:55 PM
  4. Simple thread object model (my first post)
    By Codeplug in forum Windows Programming
    Replies: 4
    Last Post: 12-12-2004, 10:34 PM
  5. Thread Synchronization :: Win32 API vs. MFC
    By kuphryn in forum Windows Programming
    Replies: 2
    Last Post: 08-09-2002, 09:09 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21