gpt4 book ai didi

c++ - MicroBlaze 上 C++ 的线程安全

转载 作者:塔克拉玛干 更新时间:2023-11-03 01:47:09 24 4
gpt4 key购买 nike

有没有人为 MicroBlaze 编写过多线程 C++ 应用程序? Xilinx 文档指出:

The standard C library provided with EDK is not built for a multi-threaded environment. STDIO functions like printf(), scanf() and memory management functions like malloc() and free() are common examples of functions that are not thread-safe. When using the C library in a multi-threaded environment, proper mutual exclusion techniques must be used to protect thread unsafe functions.

此外,MicroBlaze GCC 报告线程模型是“单一的”。

如果我使用 C++ 标准库容器,这肯定不安全,对吗?

我连从 Xilinx 那里得到这个简单问题的答案都花了不少时间,更不用说修复它的方法了。这似乎是 Xilinx 提供的构建系统的一个主要缺陷。

最佳答案

Xilinx 的回答(通过电子邮件)如下。它没有提到多线程。它还引用了他们在 2006 年(6 年前!!!)发布的软件工具 8.2i。简而言之,这没有任何意义。

经验教训:

  • Xilinx 支持很糟糕。
  • Xilinx 软件工具是他们事后才想到的。
  • 我只能假设文档中概述的内容是正确的,特别是您不能在多线程环境中使用动态内存分配。这意味着没有 C++ 标准库容器。
  • 如果您是准备选择 MicroBlaze 软核处理器的硬件人员,请在选择之前咨询固件人员。他期望编写什么样的应用程序?确保他知道他不能用 C++ 编写多线程应用程序。

malloc()

Microblaze C library shipped with a small, minimal functionality malloc(). When used, memory could not be freed. Other functions such as calloc, realloc, etc., were not supported. There were also bugs when using both malloc() and routines such as printf, scanf, etc. To fix this, the minimal functionality malloc() has been removed. It has been replaced by original Newlib malloc(). As a result, you should see NO functionality issues. You might see a code size increase of around 4K. Because of the differences in which the new full functionality malloc() requests memory, user programs might need to review their heap size settings. If you see your malloc() calls returning NULL, where they used to work, try increasing your heap size. This change was essential to fix broken functionality.

For the rare cases where you still want the original light-weight, but broken malloc() functionality, the source code (malloc.S) can be included as one of the source files to be compiled to build your application. This will retain the old functionality, code size requirements, and dynamic memory requirements seen prior to EDK 8.2i.

xil_malloc()

MicroBlaze C library shipped with an alternative implementation of dynamic memory allocation called xil_malloc(). This routine has some limitations; it does not allocate memory from the heap, but rather from a fixed 64K buffer. This routine has now been deprecated. Though this routine is still available for linkage, its use is strongly discouraged. Please use malloc(); it is smaller than xil_malloc() and provides better functionality. When using malloc(), make sure to review your heap size settings to satisfy your dynamic memory requirements.

The standalone BSP contains a parameter "need_xil_malloc". This parameter was intended to allow you to write code that contains malloc(), yet wire it to the xil_malloc() implementation. Due to bugs in the implementation of the parameter and due to the deprecation of xil_malloc(), this parameter is deprecated as well.

Xilkernel contains a parameter "use_xil_malloc". This parameter was intended to allow the kernel message queue implementations to use xil_malloc() instead of malloc(). Due to the deprecation of xil_malloc(), this parameter is deprecated as well.

If you still want xil_malloc() source code for legacy reasons, the "xil_malloc.c" and "xil_sbrk.c" files can be downloaded and used.

C++ Applications

Prior to EDK 8.2i C++ applications might exhibit unusual behavior, memory corruption, etc. To fix these issues, include the attached source file (newlib_malloc.c) as part of your application compilation. This will fix the unexplained crashes. This work-around fixes bugs in the malloc() implementation in the MicroBlaze C library. This work-around has been incorporated into the C library starting in EDK 8.2i.

此信息似乎也可在以下位置获得:http://www.xilinx.com/support/answers/23345.html

关于c++ - MicroBlaze 上 C++ 的线程安全,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13242002/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com