linux-c-programming.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Hendrik Visage <hvjunk@gmail.com>
To: Jimmy Pan <dspjmt@gmail.com>
Cc: linux-newbie@vger.kernel.org, linux-c-programming@vger.kernel.org
Subject: Re: How does atomic operation work on smp
Date: Wed, 7 Nov 2012 18:26:24 +0200	[thread overview]
Message-ID: <CADtGFvkoVX-CCEPRE7swRFiTeBo2wFiQx_8S5woKp_ts8XsUUA@mail.gmail.com> (raw)
In-Reply-To: <20121108070121.GA7492@gmail.com>

On Thu, Nov 8, 2012 at 9:01 AM, Jimmy Pan <dspjmt@gmail.com> wrote:
> I understand how atomic operation work on unary core processors, I think it just disables the interrupt and dominate the cpu until it finished.
> While, how do we implement this on multi processor computers?
> Suppose cpu A is performing an atomic operation on variable a. At the same time, cpu B is also performing the operation on a. In such the result may be overwritten.
> Of course we can use spinlocks, but on the atomic operation's behalf, how does it gurantee to prevent such case?
> Can anyone explain the crux of it? Thanks.

Basically you make use of machine specific instructions that will  do
that for you.
In other words, get the datasheets of the specific system you intent
to code on/for (I assume here you are refering to assembler level
codes, as higher up you make use of the relevant libraries that does
that for you).

However, if you refer to the general case: You make use of critical
areas bounded by the necessary lock(s), like semaphores, mutex locks,
doors, message queues etc. that is described in details in several
text books on the subject of concurrency/parallelism/distributed
computing/etc.
--
To unsubscribe from this list: send the line "unsubscribe linux-newbie" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.linux-learn.org/faqs

  reply	other threads:[~2012-11-07 16:26 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-11-08  7:01 How does atomic operation work on smp Jimmy Pan
2012-11-07 16:26 ` Hendrik Visage [this message]
2012-11-07 16:45   ` Nicholas Mc Guire
2012-11-08 17:42     ` anish kumar

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=CADtGFvkoVX-CCEPRE7swRFiTeBo2wFiQx_8S5woKp_ts8XsUUA@mail.gmail.com \
    --to=hvjunk@gmail.com \
    --cc=dspjmt@gmail.com \
    --cc=linux-c-programming@vger.kernel.org \
    --cc=linux-newbie@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).