简体   繁体   English

MicroBlaze上C ++的线程安全性

[英]Thread safety of C++ on MicroBlaze

Has any one ever written a multi-threaded C++ application for MicroBlaze? 有没有人为MicroBlaze编写过多线程的C ++应用程序? The Xilinx documentation states that: Xilinx文档指出:

The standard C library provided with EDK is not built for a multi-threaded environment. EDK提供的标准C库不是为多线程环境构建的。 STDIO functions like printf(), scanf() and memory management functions like malloc() and free() are common examples of functions that are not thread-safe. 像printf(),scanf()和内存管理函数(如malloc()和free())之类的STDIO函数是非线程安全函数的常见示例。 When using the C library in a multi-threaded environment, proper mutual exclusion techniques must be used to protect thread unsafe functions. 在多线程环境中使用C库时,必须使用适当的互斥技术来保护线程不安全的函数。

Additionally, MicroBlaze GCC reports that the thread model is "single." 此外,MicroBlaze GCC报告线程模型是“单一的”。

If I'm using C++ standard library containers, this is surely unsafe, correct? 如果我使用C ++标准库容器,这肯定是不安全的,对吗?

I'm having a heck of time even getting an answer to this simple question from Xilinx, let alone a way to fix it. 我对Xilinx提出的这个简单问题的答案感到很难,更不用说修复它了。 It seems that this is a major deficiency of the Xilinx provided build system. 这似乎是Xilinx提供的构建系统的一个主要缺陷。

The answer from Xilinx (via email) is below. Xilinx(通过电子邮件)的答案如下。 It makes no mention of multi-threading. 它没有提到多线程。 It also references a their software tool 8.2i which was released in 2006 (6 years ago!!!). 它还引用了他们在2006年发布的软件工具8.2i(6年前!!!)。 In short, it makes no sense. 简而言之,这没有任何意义。

Lessons learned: 得到教训:

  • Xilinx support is terrible. Xilinx支持非常糟糕。
  • Xilinx software tools are an afterthought for them. Xilinx软件工具是他们的事后想法。
  • I can only assume that what is outlined in documentation is correct, specifically that you cannot use dynamic memory allocation in a multi-threaded environment. 我只能假设文档中概述的内容是正确的,特别是您不能在多线程环境中使用动态内存分配。 This means no c++ standard library containers. 这意味着没有c ++标准库容器。
  • If you're the hardware guy about to select a MicroBlaze soft core processor, check with the firmware guy before you do that. 如果您是要选择MicroBlaze软核处理器的硬件人员,请在执行此操作之前与固件人员联系。 What kind of applications is he expecting to write? 他期望写什么样的应用程序? Make sure he knows that he can't write a multi-threaded application in C++. 确保他知道他不能用C ++编写多线程应用程序。

malloc() 的malloc()

Microblaze C library shipped with a small, minimal functionality malloc(). Microblaze C库附带一个小的,最小的功能malloc()。 When used, memory could not be freed. 使用时,无法释放内存。 Other functions such as calloc, realloc, etc., were not supported. 不支持其他函数,如calloc,realloc等。 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. 使用malloc()和例程如printf,scanf等时也存在错误。为了解决这个问题,已经删除了最小功能malloc()。 It has been replaced by original Newlib malloc(). 它已被原始的Newlib malloc()取代。 As a result, you should see NO functionality issues. 因此,您应该看到没有功能问题。 You might see a code size increase of around 4K. 您可能会看到代码大小增加大约4K。 Because of the differences in which the new full functionality malloc() requests memory, user programs might need to review their heap size settings. 由于新的完整功能malloc()请求内存的差异,用户程序可能需要查看其堆大小设置。 If you see your malloc() calls returning NULL, where they used to work, try increasing your heap size. 如果你看到你的malloc()调用返回NULL,他们曾经在那里工作,尝试增加你的堆大小。 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. 对于您仍然需要原始轻量级但破坏的malloc()功能的极少数情况,源代码(malloc.S)可以作为要编译的源文件之一包含在构建应用程序中。 This will retain the old functionality, code size requirements, and dynamic memory requirements seen prior to EDK 8.2i. 这将保留EDK 8.2i之前的旧功能,代码大小要求和动态内存要求。

xil_malloc() xil_malloc()

MicroBlaze C library shipped with an alternative implementation of dynamic memory allocation called xil_malloc(). MicroBlaze C库附带了一个名为xil_malloc()的动态内存分配的替代实现。 This routine has some limitations; 这个例程有一些局限性; it does not allocate memory from the heap, but rather from a fixed 64K buffer. 它不会从堆中分配内存,而是从固定的64K缓冲区分配内存。 This routine has now been deprecated. 此例程现已弃用。 Though this routine is still available for linkage, its use is strongly discouraged. 尽管此例程仍可用于链接,但强烈建议不要使用它。 Please use malloc(); 请使用malloc(); it is smaller than xil_malloc() and provides better functionality. 它小于xil_malloc()并提供更好的功能。 When using malloc(), make sure to review your heap size settings to satisfy your dynamic memory requirements. 使用malloc()时,请务必检查堆大小设置以满足动态内存要求。

The standalone BSP contains a parameter "need_xil_malloc". 独立BSP包含参数“need_xil_malloc”。 This parameter was intended to allow you to write code that contains malloc(), yet wire it to the xil_malloc() implementation. 此参数旨在允许您编写包含malloc()的代码,并将其连接到xil_malloc()实现。 Due to bugs in the implementation of the parameter and due to the deprecation of xil_malloc(), this parameter is deprecated as well. 由于参数实现中的错误以及xil_malloc()的弃用,此参数也已弃用。

Xilkernel contains a parameter "use_xil_malloc". Xilkernel包含一个参数“use_xil_malloc”。 This parameter was intended to allow the kernel message queue implementations to use xil_malloc() instead of malloc(). 此参数旨在允许内核消息队列实现使用xil_malloc()而不是malloc()。 Due to the deprecation of xil_malloc(), this parameter is deprecated as well. 由于xil_malloc()的弃用,此参数也已弃用。

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. 如果由于遗留原因仍需要xil_malloc()源代码,则可以下载并使用“xil_malloc.c”和“xil_sbrk.c”文件。

C++ Applications C ++应用程序

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. 在EDK 8.2i之前,C ++应用程序可能会出现异常行为,内存损坏等。要解决这些问题,请将附加的源文件(newlib_malloc.c)作为应用程序编译的一部分。 This will fix the unexplained crashes. 这将解决原因不明的崩溃。 This work-around fixes bugs in the malloc() implementation in the MicroBlaze C library. 这种解决方法修复了MicroBlaze C库中malloc()实现中的错误。 This work-around has been incorporated into the C library starting in EDK 8.2i. 从EDK 8.2i开始,这种解决方法已经整合到C库中。

This information also appears to be available at: http://www.xilinx.com/support/answers/23345.html 此信息似乎也可从以下网址获得: http//www.xilinx.com/support/answers/23345.html

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM