This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

Why we need CLREX in exception handler?

Note: This was originally posted on 15th October 2012 at http://forums.arm.com

Dear Sirs:

We check the state diagram and don't know why we need to perform CLREX in  exception handler;
1. once another thread success did the STOREX before the original thread performed the exception handler. The original thread would execute STOREX fail after finished the exception handler.
2. If there is no thread did the STOREX, the original thread could success execute STOREX and perform the exclusive access.

Why we need CLREX in exception handler? Do I miss anything?

Regards
Liang
  • Note: This was originally posted on 16th October 2012 at http://forums.arm.com

    Dear Isogen74:

    Thanks for your reply in detail. Help us to clarify our thinking.

    Regards
    Liang
  • Note: This was originally posted on 15th October 2012 at http://forums.arm.com

    R.e. (1) Yes, the issue isn't the thread you are switching out, it is the thread you are switching in. Consider:

    You can have an implementation of an exclusive monitor on a uni-processor system without an address tag. You pre-empt a thread which has loaded exclusive A, but not yet stored it. The exclusive monitor is set because the store has not happened yet. You restore a thread which previously loaded exclusive B at a totally different address and run it's exclusive store. This succeeds because the exclusive monitor is still set from Thread A. Given a third thread may have already modified exclusive B (between the load and (possibly much later) store of the second thread) you've just corrupted memory - leaving the exclusive bit set is not thread safe..

    R.e. (2) You can't design a computer architecture which is robust based on comments like "if there is no thread ...". The OS doesn't know if the thread it switches in will use STREX or not. To ensure reliable operation it has to assume that it will.

    Clrex ensure that the thread which is just switched in always fails the store, and retries with the latest state in memory - i.e. gets the latest version.