Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.java.programmer > #3371

Re: A question about synchronized threads

From byhesed <byhesed@gmail.com>
Newsgroups comp.lang.java.programmer
Subject Re: A question about synchronized threads
Date 2011-04-29 18:43 -0700
Organization http://groups.google.com
Message-ID <2d4cb21d-ba59-48cf-897c-b9d7e61a984e@r27g2000prr.googlegroups.com> (permalink)
References <3f249d87-aaf8-4732-9ee8-fd112cf82553@f31g2000pri.googlegroups.com> <ipemsm$7nc$1@news.albasani.net> <8b7289b0-2b52-44f9-96a9-fe1d2661de11@k3g2000prl.googlegroups.com> <ipfn1m$gvd$1@dont-email.me>

Show all headers | View raw


On 4월30일, 오전10시01분, Eric Sosman <esos...@ieee-dot-org.invalid> wrote:
> On 4/29/2011 12:12 PM, byhesed wrote:
>
> > [...]
> > If too much spaces are marked as critical regions,
> > then the program will not be optimized.
> > It wastes too much time in waiting for obtaining a right to access
> > critical regions.
>
> > So, in my question, better means optimization when using threads.
>
>      A bit of advice I've found *very* useful over the years: Don't
> think about protecting "critical regions of code," think instead
> about protecting "access to shared data."
>
>      Stop.  Go back and read the paragraph again.  It's the crux.
>
>      Threads T1,T2,...,Tn do not interfere by executing the same
> code simultaneously, but by trying to access the same data.  (More
> generally, by trying to access the same "state.")  If the shared
> state is S, then T1,T2,...,Tn must not try to alter it at the same
> time, nor try to read it while another Tx is altering it.  If, on
> the other hand, S decomposes into disjoint sub-states S1,S2,...,Sm
> that are *completely* independent, then it's all right for Ti to
> alter Sa while Tj reads Sb; you must guard against simultaneous
> alteration or alteration-and-read of each single sub-state Sx.
>
>      Think about the state; that's what you're trying to keep
> coherent and consistent.  Don't worry about the code; it's just
> the tool that manipulates the state.  You'll be astonished at how
> much simpler things become with this view.  Trust me.
>
> --
> Eric Sosman
> esos...@ieee-dot-org.invalid

Thank you for your advice.

I'll remember what you recommend:
"Think instead about protecting "access to shared data."

Back to comp.lang.java.programmer | Previous | NextPrevious in thread | Next in thread | Find similar


Thread

A question about synchronized threads byhesed <byhesed@gmail.com> - 2011-04-29 08:35 -0700
  Re: A question about synchronized threads Lew <noone@lewscanon.com> - 2011-04-29 11:53 -0400
    Re: A question about synchronized threads byhesed <byhesed@gmail.com> - 2011-04-29 09:12 -0700
      Re: A question about synchronized threads Eric Sosman <esosman@ieee-dot-org.invalid> - 2011-04-29 21:01 -0400
        Re: A question about synchronized threads byhesed <byhesed@gmail.com> - 2011-04-29 18:43 -0700
  Re: A question about synchronized threads Daniele Futtorovic <da.futt.news@laposte-dot-net.invalid> - 2011-04-29 17:58 +0200
    Re: A question about synchronized threads byhesed <byhesed@gmail.com> - 2011-04-29 09:09 -0700
      Re: A question about synchronized threads markspace <-@.> - 2011-04-29 11:11 -0700
        Re: A question about synchronized threads Daniele Futtorovic <da.futt.news@laposte-dot-net.invalid> - 2011-04-29 20:19 +0200
          Re: A question about synchronized threads markspace <-@.> - 2011-04-29 15:21 -0700
          Re: A question about synchronized threads Patricia Shanahan <pats@acm.org> - 2011-04-29 21:10 -0700
  Re: A question about synchronized threads dagon@dagon.net (Dagon) - 2011-04-29 15:55 -0700
    Re: A question about synchronized threads Alice <quaxx1108@example.com> - 2011-04-29 20:08 -0400
    Re: A question about synchronized threads markspace <-@.> - 2011-04-29 19:07 -0700
    Re: A question about synchronized threads byhesed <byhesed@gmail.com> - 2011-04-29 18:49 -0700
      Re: A question about synchronized threads Lew <noone@lewscanon.com> - 2011-05-03 18:57 -0400
        Re: A question about synchronized threads Deeyana <d.awlberg@hotmail.invalid> - 2011-05-04 00:17 +0000
          Re: A question about synchronized threads Lew <noone@lewscanon.com> - 2011-05-04 12:45 -0400
            Re: A question about synchronized threads Deeyana <d.awlberg@hotmail.invalid> - 2011-05-04 19:59 +0000

csiph-web