Unix Programming - spinlock vs test and set instruction

This is Interesting: Free IT Magazines  
Home > Archive > Unix Programming > January 2005 > spinlock vs test and set instruction





You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

Author spinlock vs test and set instruction
puzzlecracker

2005-01-22, 8:48 pm

Is spin lock different from test and set instruction (used to implement
mutex)? What are the uses of spinlock?
Textbook was really confusing about these issues.
Thanks.

Måns Rullgård

2005-01-22, 8:48 pm

"puzzlecracker" <ironsel2000@gmail.com> writes:

> Is spin lock different from test and set instruction (used to implement
> mutex)? What are the uses of spinlock?


Is a car different from a gearbox?

--
Måns Rullgård
mru@inprovide.com
puzzlecracker

2005-01-22, 8:48 pm


M=E5ns Rullg=E5rd wrote:
> "puzzlecracker" <ironsel2000@gmail.com> writes:
>
implement[vbcol=seagreen]
>
> Is a car different from a gearbox?
>
> --
> M=E5ns Rullg=E5rd
> mru@inprovide.com



Didn't we already have this discussion? You don't need to respect me
nor my question. But please show some undestanding to others, who might
be reading it, and who share equal confusion in the area.

THanks

Måns Rullgård

2005-01-22, 8:48 pm

"puzzlecracker" <ironsel2000@gmail.com> writes:

> Måns Rullgård wrote:
>
> Didn't we already have this discussion?


Yes, we did, and apparently you didn't pay attention.

> You don't need to respect me nor my question. But please show some
> undestanding to others, who might be reading it, and who share equal
> confusion in the area.


My advice to those, as well as to you, is to read a good book, and do
some experiments. If you still don't understand, ask specific
questions, and include example code you are having trouble with.
Nobody is going to write a book on programming, right here on the
Usenet, just for you.

--
Måns Rullgård
mru@inprovide.com
Jim Cochrane

2005-01-22, 8:48 pm

In article <yw1xis5pkmmo.fsf@ford.inprovide.com>, Måns Rullgård wrote:
> "puzzlecracker" <ironsel2000@gmail.com> writes:
>
>
> Yes, we did, and apparently you didn't pay attention.
>
>
> My advice to those, as well as to you, is to read a good book, and do
> some experiments. If you still don't understand, ask specific
> questions, and include example code you are having trouble with.
> Nobody is going to write a book on programming, right here on the
> Usenet, just for you.


Unless perhaps you (OP) agree to pay him/her for it. It'd be unusual to see
this take place on usenet, though. :-)

--
Jim Cochrane; jtc@dimensional.com
[When responding by email, include the term non-spam in the subject line to
get through my spam filter.]
DINH Viet Hoa

2005-01-22, 8:48 pm

puzzlecracker wrote :

> Is spin lock different from test and set instruction (used to implement
> mutex)? What are the uses of spinlock?
> Textbook was really confusing about these issues.
> Thanks.


In short, test and set instruction is hardly available to the programmer
at high-level language (high means starting from (and including) C).
Locks will often be implemented using test and set instructions.

Spin locks is one variant of locks. This is CPU-consuming but performant
in most case. Get some book on operating systems and read chapters on
locks and sharing of resource.

--
DINH V. Hoa,

"s/^\(\(\\.\|[^\[]\|\[\(\^.\|[^^]\)[^]]*\]\)*\)\(\\[^\*[]\)/\1\\\4/"
-- Stéphane CHAZELAS

Barry Margolin

2005-01-23, 2:48 am

In article <yw1xis5pkmmo.fsf@ford.inprovide.com>,
Måns Rullgård <mru@inprovide.com> wrote:

> My advice to those, as well as to you, is to read a good book,


His original message said that he read a textbook, but didn't understand
it. Coming here for further clarification seems like a reasonable next
step.

What bugs me is that he multi-posted the question. I just answered him
in another newsgroup (comp.unix.internals, I think).

--
Barry Margolin, barmar@alum.mit.edu
Arlington, MA
*** PLEASE post questions in newsgroups, not directly to me ***
puzzlecracker

2005-01-23, 2:48 am


Barry Margolin wrote:
> In article <yw1xis5pkmmo.fsf@ford.inprovide.com>,
> M=E5ns Rullg=E5rd <mru@inprovide.com> wrote:
>
>
> His original message said that he read a textbook, but didn't

understand
> it. Coming here for further clarification seems like a reasonable

next
> step.
>
> What bugs me is that he multi-posted the question. I just answered

him
> in another newsgroup (comp.unix.internals, I think).
>
> --
> Barry Margolin, barmar@alum.mit.edu
> Arlington, MA
> *** PLEASE post questions in newsgroups, not directly to me ***


Thanks so much.

I did multipost simply to express the gravity of my confusion and
these two groups seem to be a best fit. Therefore, I wasn't sure!

Again, many thanks.




> His original message said that he read a textbook, but didn't

understand
> it. Coming here for further clarification seems like a reasonable

next
> step.

Barry, I couldn't agree more with that.

Just a small follow-up: is test and set CPU consuming instruction?

P=2ES.: I will lastly multi-post and Then I will stick with one group at
a time....

Gianni Mariani

2005-01-23, 2:48 am

puzzlecracker wrote:
> Is spin lock different from test and set instruction (used to implement
> mutex)? What are the uses of spinlock?
> Textbook was really confusing about these issues.
> Thanks.
>


http://en.wikipedia.org/wiki/Spinlock

http://msdn.microsoft.com/library/d...areexchange.asp

Måns Rullgård

2005-01-23, 2:48 am

Barry Margolin <barmar@alum.mit.edu> writes:

> In article <yw1xis5pkmmo.fsf@ford.inprovide.com>,
> Måns Rullgård <mru@inprovide.com> wrote:
>
>
> His original message said that he read a textbook, but didn't understand
> it. Coming here for further clarification seems like a reasonable next
> step.


Maybe his book wasn't a good one. In either case, his question was
much too broad to expect a good answer here. Maybe this question
could have been acceptable, had he not been posting a zillion
generic questions on trivial things over the last few days.

--
Måns Rullgård
mru@inprovide.com
DINH Viet Hoa

2005-01-23, 7:47 am

puzzlecracker wrote :

> Thanks so much.
>
> I did multipost simply to express the gravity of my confusion and
> these two groups seem to be a best fit. Therefore, I wasn't sure!


post one time in the proper newsgroup, where we read that there is much
activity. comp.unix.programmer is a newsgroup with such activity.

> Just a small follow-up: is test and set CPU consuming instruction?


(Please follow-up on the concerned message, this is easier to read)
given a test and set instruction : test_and_test(variable).
This instruction will succeed only if variable is set to FALSE.
This will set it to TRUE if this is the case.
This instruction returns TRUE if it succeeded, FALSE if it failed.

spin lock is implemented the following way:

spin_lock(lock)
{
while (!test_and_set(lock)) {
/* do nothing */
}
}

spin_unlock(lock)
{
lock = FALSE;
}

and try to understand why spin_lock() would be CPU consuming.

> P.S.: I will lastly multi-post and Then I will stick with one group at
> a time....


This is not that easy when people answer on much different groups.
Followup-to information is here for this purpose.

Is the behavior to adopt described in netiquette ?

--
DINH V. Hoa,

"en plus je me drogue pas au fromage blanc moi monsieur" -- voisin

mick

2005-01-23, 5:50 pm

> Is spin lock different from test and set instruction (used to implement
> mutex)? What are the uses of spinlock?
> Textbook was really confusing about these issues.
> Thanks.



Here's a thought for you, If I were setting these questions for you
I'd'h've set up a search of the relevant newsgroups to catch any of my
students soliciting answers. "How do you explain this you sniveling excuse
for...I'm grading all your units..etc...pass me the switch nurse I'm
re-instating corporal punishment"


Rich Teer

2005-01-23, 5:50 pm

On Sat, 22 Jan 2005, puzzlecracker wrote:

> I did multipost simply to express the gravity of my confusion and
> these two groups seem to be a best fit. Therefore, I wasn't sure!


In that case, the correct thing to do is crosspost, not multi post.

--
Rich Teer, SCNA, SCSA, author of "Solaris Systems Programming"

President,
Rite Online Inc.

Voice: +1 (250) 979-1638
URL: http://www.rite-group.com/rich
Sponsored Links






Free braindumps | Software forum | Database administration forum

Copyright 2003 - 2008 webservertalk.com