Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8823743
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T06:26:03+00:00 2026-06-14T06:26:03+00:00

I have a question about mutex implementation in Linux kernel on an ARM platform.

  • 0

I have a question about mutex implementation in Linux kernel on an ARM platform.

__mutex_fastpath_lock(atomic_t *count, void (*fail_fn)(atomic_t *))
{
    int __ex_flag, __res;

    __asm__ (

             "ldrex  %0, [%2]        \n\t"
             "sub    %0, %0, #1      \n\t"
             "strex  %1, %0, [%2]    "  //for ARMv6+ ,kernel use ldrex/strex implement mutex lock.

              : "=&r" (__res), "=&r" (__ex_flag)
              : "r" (&(count)->counter)
              : "cc","memory" );

             __res |= __ex_flag;    //How can we know the "strex" operation is successfully finished or not? 
                                    //The status of (atomic_t *count) is different in these two cases. 
                                    //I wonder this is a bug ,or I did not understand the lock mechanism so well.

      if (unlikely(__res != 0))
           fail_fn(count);
      }

Thank you very much for your suggestion or answer to this question. Anything will be appreciated.

For more information about the source code, please refer to ; http://lxr.oss.org.cn/source/arch/arm/include/asm/mutex.h?v=3.5.2;a=arm

The file path is:

linux-3.5.2/arch/arm/include/asm/mutex.h
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T06:26:04+00:00Added an answer on June 14, 2026 at 6:26 am

    __res is zero if successful

    STREX{cond} Rd, Rm, [Rn] Store to address in Rn and flag if successful in Rd
    (Rd = 0 if successful)

    Note that __res is or’d with __ex_flag

     __res |= __ex_flag;
    

    So if either of the ldrex or strex operations has failed the check fails.

    Note: if the value was accessed after ldrex the exclusive access fails; strex fails and the value will not be stored. There’s more information about this in the info center:

    The STREX instruction performs a conditional store of a word to
    memory. If the exclusive monitor(s) permit the store, the operation
    updates the memory location and returns the value 0
    in the destination
    register, indicating that the operation succeeded. If the exclusive
    monitor(s) do not permit the store, the operation does not update the
    memory location and returns the value 1
    in the destination register.

    The point is that if the exclusive access fails, either on load or store the kernel will know about it because __ex_flags=1 or __res=1, if it doesn’t fail, but the mutex was already locked we will still know about it because __res=0xFFFFFFFF at that point it doesn’t matter if the exclusive access has failed or not because the mutex was locked.

    Now, the only problem I see is that it will store 0xFFFFFFFF into count, but that will probably be incremented again when whoever locked the mutex unlocks it, which means it could be a way for more than one thread to wait on the mutex. This is from the comments in your link:

    If once decremented it isn’t zero, or if its store-back fails due to a
    dispute on the exclusive store
    , we simply bail out immediately through
    the slow path where the lock will be reattempted until it succeeds.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a question about Windows IPC. I implemented IPC with mutex on Windows,
Good evening fellow stackers, I have a mutex and threaded related question about //
I have a question about the relationship between header and implementation files in C++.
I have question about parsing in Html helper : I have sth like: @foreach
I have question about clean thory in Python. When: @decorator_func def func(bla, alba): pass
I have question about XSLT1.0. The task is to write out in HTML all
I have question about normalization. Suppose I have an applications dealing with songs. First
I have question about interpreting strings as packed binary data in C++. In python,
i have question about YAJLiOS parser... I have next json data : {{ body
I have a question about this formula from a book: EFW (cm,kg)= 10^(-1,7492+(0,166*BPD)+(0,046*AC)-(2,646*AC*BPD/1000)) The

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.