# Thread safe memory allocation

**URL:** <https://forums.freertos.org/t/thread-safe-memory-allocation/8003>\
**Category:** Kernel\
**Created:** [August 9, 2019, 1:14pm UTC](https://forums.freertos.org/t/thread-safe-memory-allocation/8003 "2019-08-09T13:14:31Z")\
**Posts on this page:** 1\
**Showing post:** 6

<div class="post-metadata">

**Author:** ![system](https://d2v6vdsk2p900z.cloudfront.net/original/1X/7fc8fdb729c645aab5b20282bbe34e57cb407be6.jpeg) [@system](https://forums.freertos.org/u/system)\
**Post date:** [August 19, 2019, 8:44am UTC](https://forums.freertos.org/t/thread-safe-memory-allocation/8003/6 "2019-08-19T08:44:10Z")

</div>

**[parmi](https://sourceforge.net/u/parmi/)** wrote on [Monday, August 19, 2019](https://sourceforge.net/p/freertos/discussion/382005/thread/ee6e69d6ea/#e905):

I tried to define the **malloc\_lock** and **malloc\_unlock** functions, but the linker gives me an error.

**main.cpp**

```auto
extern "C" void __malloc_lock(struct _reent *REENT)
{
	vPortEnterCritical();
}

extern "C" void __malloc_unlock(struct _reent *REENT)
{
	vPortExitCritical();
}

```

Linking error:

```auto
1>Linking ../MyProject/...
1>c:/sysgcc/arm-eabi/bin/../lib/gcc/arm-eabi/7.2.0/../../../../arm-eabi/lib/thumb/cortex_m4\libc_nano.a(lib_a-mlock.o): In function `__malloc_lock':
1>q:\gnu\newlib-nano\gcc-arm-none-eabi-6-2017-q2-update\src\newlib\newlib\libc\stdlib\mlock.c(53): error : multiple definition of `__malloc_lock'
1>VisualGDB/Debug/main.o:C:\visual_gdb_workspace\MyProject\MyProject/main.cpp:130: first defined here
1>collect2.exe : error : ld returned 1 exit status

```

---

_[View the full topic](https://forums.freertos.org/t/thread-safe-memory-allocation/8003)._
