Re: read-write mutex



On Jan 9, 9:08 am, snovgorod...@xxxxxxxxx wrote:
On Jan 8, 3:47 pm, David Schwartz <dav...@xxxxxxxxxxxxx> wrote:> On Jan 8, 9:05 am, snovgorod...@xxxxxxxxx wrote:

I guess my question is why would I need a mutex in case of multiple
readers/single writer?

Because the pthreads standard says that the results of one thread
reading from a variable while another thread is or might be modifying
it is undefined.

Could you plz give me an example of such undefined result?

The program crashes. The computer catches on fire. Your dog gets
pregnant.

An "undefined result" means that anything at all can happen without
violating the standard.

I assumed that 'undefined' in this case means my reader threads
either
still read zero from the var or read some value which may be a result
of an incomplete write(var!=0).

Your assumption may be correct for some particular combination of
hardware, compiler, system libraries and so on.

Both cases are acceptable for my app, that's why I didn't use the
mutex.
I tried to avoid any decrease in performance , I thought (may be
incorrectly) that I would slow down my app, running a hundred threads
that read the variable often
and do lock/unlock every time.

That sounds like a bad design. Maybe you should fix the design so you
don't have such contention hotspots. If proper locking is impacting
performance, there's a good chance the architecture is bad.

DS
.



Relevant Pages

  • Re: GOOD BOOKS OF VB2005
    ... Overall, I'd have to say I learned a lot from reading the book, and will ... Basic 2005 as You Design and Develop a Complete Application. ... how to set up the Business objects, binding them to the controls ... through controls, how to use code snippets, etc. ...
    (microsoft.public.dotnet.languages.vb)
  • Re: OT: History--Cincinnati telephone exchange districts--dial cutover?
    ... I was just reading through some web sites on a couple of demolishedmallsnear where I grew up. ... a great design that should have been saved. ... as I had posted on Southern California malls here ...
    (misc.transport.road)
  • Re: Microsoft Access has bad image import, and no image transparen
    ... OLE Objects simply wrap various types of files and store them. ... some specific enhancements to image handling in reports. ... You can prevent users from modifying ... the design: ...
    (microsoft.public.access.reports)
  • Re: Software weenie wants to learn Mechanical Engineering...
    ... wanting to design and build all sorts of things (I've modeled various ... mechanical world before your detour into the programming world (& any ... the job" than by reading and trial & error. ... Getting to "basic skills level" by reading is probably harder & takes ...
    (sci.engr.mech)
  • Re: transition from programmer to developer
    ... Applied Object Oriented Analysis and Design Using UML", ... Reading a lot of books - I happen to have a very similar book - isn't a bad ...
    (comp.lang.java.programmer)