C ++ Thread Safety on MicroBlaze

Has anyone ever written a multithreaded C ++ application for MicroBlaze? The Xilinx documentation states that:

The standard C library provided with EDK is not designed for multi-threaded environments. STDIO functions such as printf (), scanf (), and memory management functions such as malloc () and free () are common examples of functions that are not thread safe. When using the C library in a multi-threaded environment, you must use the appropriate mutual exclusion methods to protect unsafe functions.

In addition, MicroBlaze GCC reports that the stream model is "single."

If I use the containers of the standard C ++ library, it is certainly unsafe, right?

I have time even getting the answer to this simple question from Xilinx, not to mention how to fix it. This seems to be the main drawback of the Xilinx build system provided.

+4
source share
1 answer

The response from Xilinx (via email) is given below. He does not mention multithreading. He also refers to their 8.2i software tool, which was released in 2006 (6 years ago !!!). In short, this makes no sense.

Lessons learned:

  • Xilinx support is terrible.
  • Xilinx software tools are an afterthought for them.
  • I can only assume that what is described in the documentation is correct, in particular, that you cannot use dynamic memory allocation in a multi-threaded environment. This means that there are no standard C ++ library containers.
  • If you are a hardware guy who wants to choose a MicroBlaze microprocessor processor, consult the firmware developer before you do this. What applications does he plan to write? Make sure he knows that he cannot write a multi-threaded application in C ++.

taNos ()

The Microblaze C library comes with a little taNos () minimal functionality. When used, the memory cannot be freed. Other functions since calloc, realloc, etc. not supported. There were also errors when using both malloc () and routines such as printf, scanf, etc. To fix this, the minimum malloc () functionality has been removed. It has been replaced by the original Newlib malloc (). As a result, you should see NO functionality issues. You can see the increase in code size around 4K. Due to the differences in which the new full malloc () functionality is requesting memory, user programs may need to look at their heap size settings. If you see your malloc () calls return NULL where they worked, try increasing the heap size. This change was important to eliminate broken functionality.

In rare cases, when you still want the original lightweight, but the malloc () functionality fails, the source code (malloc.S) can be included as one of the source files to compile to expression. This will preserve the old features, requirement code size, and dynamic memory requirements observed prior to EDK 8.2i.

xil_malloc ()

The MicroBlaze C library comes with an alternative implementation of dynamic memory allocation called xil_malloc (). This procedure has some limitations; it does not allocate memory from the heap, but rather from a fixed 64K buffer. This procedure is now outdated. Although this procedure is still available for communication, its use is strongly discouraged. Use malloc (); it is smaller than xil_malloc () and provides better functionality. When using malloc (), be sure to review the heap size settings to suit the dynamic memory requirements.

The standalone BSP contains the parameter "need_xil_malloc". This parameter should have allowed you to write code that contains malloc (), but connect it to the xil_malloc () implementation. Due to errors in the implementation of the parameter and due to obsolescence of xil_malloc (), this parameter is also deprecated.

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

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

C ++ Applications

Prior to EDK 8.2i, C ++ applications may exhibit unusual behavior, memory corruption, etc. To resolve these issues, include the attached source file (newlib_malloc.c) as part of your compilation of the application. This will eliminate unexplained accidents. This fix fixes bugs in the implementation of malloc () in the MicroBlaze C library. This workaround has been included in the C library since EDK 8.2i.

This information is also available at: http://www.xilinx.com/support/answers/23345.html

+4
source

Source: https://habr.com/ru/post/1444228/


All Articles