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

Ensure thread safety in ARM C/C++ libraries

Dear forum,
right now I am struggling with enabling thread safety for my ARM C/C++ libraries.

Here's the problem I am facing:
Actually I am running a multithreaded application on my Cortex-M3 device.
I am facing spontaneous crashes and suspect the source of these crashes rooted inside the C or C++ library.

As a solution I am trying to make the libraries thread safe as described here:
[1]
http://www.keil.com/support/man/docs/armlib/armlib_Chdcgdbh.htm
and here:
[2]
http://www.keil.com/support/man/docs/armlib/armlib_Chdfjddj.htm

Actually I tried to implement [2] by writing
extern "C" int _mutex_initialize(int* p_pMutex)
{ return 1;
}

inside my main.cpp file.
The problem is that _mutex_initialize is never called. Is there a special switch or anything that I have turn to force the C library calling my _mutex_initialize function?

Many thanks in advance and best regards
Jan

Parents
  • Hello

    The ARM library references _mutex_initialize with a weak reference.

    Therefore, the linker will remove this function unless your code references it. I don't remember how I solved it in my code, but maybe it is as simple as calling it in your main with null arguments.

    Remember to return 1 from the function, if you don't the library won't use the mutex.

    void main(void)
    { _mutex_initialize(NULL);

    ....

    }

Reply
  • Hello

    The ARM library references _mutex_initialize with a weak reference.

    Therefore, the linker will remove this function unless your code references it. I don't remember how I solved it in my code, but maybe it is as simple as calling it in your main with null arguments.

    Remember to return 1 from the function, if you don't the library won't use the mutex.

    void main(void)
    { _mutex_initialize(NULL);

    ....

    }

Children
No data