草庐IT

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

coder 2024-02-20 原文

有没有人为 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/

有关c++ - MicroBlaze 上 C++ 的线程安全的更多相关文章

  1. ruby-on-rails - 如何优雅地重启 thin + nginx? - 2

    我的瘦服务器配置了nginx,我的ROR应用程序正在它们上运行。在我发布代码更新时运行thinrestart会给我的应用程序带来一些停机时间。我试图弄清楚如何优雅地重启正在运行的Thin实例,但找不到好的解决方案。有没有人能做到这一点? 最佳答案 #Restartjustthethinserverdescribedbythatconfigsudothin-C/etc/thin/mysite.ymlrestartNginx将继续运行并代理请求。如果您将Nginx设置为使用多个上游服务器,例如server{listen80;server

  2. ruby - 如何使用 Ruby aws/s3 Gem 生成安全 URL 以从 s3 下载文件 - 2

    我正在编写一个小脚本来定位aws存储桶中的特定文件,并创建一个临时验证的url以发送给同事。(理想情况下,这将创建类似于在控制台上右键单击存储桶中的文件并复制链接地址的结果)。我研究过回形针,它似乎不符合这个标准,但我可能只是不知道它的全部功能。我尝试了以下方法:defauthenticated_url(file_name,bucket)AWS::S3::S3Object.url_for(file_name,bucket,:secure=>true,:expires=>20*60)end产生这种类型的结果:...-1.amazonaws.com/file_path/file.zip.A

  3. ruby - RuntimeError(自动加载常量 Apps 多线程时检测到循环依赖 - 2

    我收到这个错误:RuntimeError(自动加载常量Apps时检测到循环依赖当我使用多线程时。下面是我的代码。为什么会这样?我尝试多线程的原因是因为我正在编写一个HTML抓取应用程序。对Nokogiri::HTML(open())的调用是一个同步阻塞调用,需要1秒才能返回,我有100,000多个页面要访问,所以我试图运行多个线程来解决这个问题。有更好的方法吗?classToolsController0)app.website=array.join(',')putsapp.websiteelseapp.website="NONE"endapp.saveapps=Apps.order("

  4. ruby - 如何安全地删除文件? - 2

    在Ruby中是否有Gem或安全删除文件的方法?我想避免系统上可能不存在的外部程序。“安全删除”指的是覆盖文件内容。 最佳答案 如果您使用的是*nix,一个很好的方法是使用exec/open3/open4调用shred:`shred-fxuz#{filename}`http://www.gnu.org/s/coreutils/manual/html_node/shred-invocation.html检查这个类似的帖子:Writingafileshredderinpythonorruby?

  5. ruby - 使用 `+=` 和 `send` 方法 - 2

    如何将send与+=一起使用?a=20;a.send"+=",10undefinedmethod`+='for20:Fixnuma=20;a+=10=>30 最佳答案 恐怕你不能。+=不是方法,而是语法糖。参见http://www.ruby-doc.org/docs/ProgrammingRuby/html/tut_expressions.html它说Incommonwithmanyotherlanguages,Rubyhasasyntacticshortcut:a=a+2maybewrittenasa+=2.你能做的最好的事情是:

  6. ruby - 如何让Ruby捕获线程中的语法错误 - 2

    我正在尝试使用ruby​​编写一个双线程客户端,一个线程从套接字读取数据并将其打印出来,另一个线程读取本地数据并将其发送到远程服务器。我发现的问题是Ruby似乎无法捕获线程内的错误,这是一个示例:#!/usr/bin/rubyThread.new{loop{$stdout.puts"hi"abc.putsefsleep1}}loop{sleep1}显然,如果我在线程外键入abc.putsef,代码将永远不会运行,因为Ruby将报告“undefinedvariableabc”。但是,如果它在一个线程内,则没有错误报告。我的问题是,如何让Ruby捕获这样的错误?或者至少,报告线程中的错误?

  7. ruby - 用 YAML.load 解析 json 安全吗? - 2

    我正在使用ruby2.1.0我有一个json文件。例如:test.json{"item":[{"apple":1},{"banana":2}]}用YAML.load加载这个文件安全吗?YAML.load(File.read('test.json'))我正在尝试加载一个json或yaml格式的文件。 最佳答案 YAML可以加载JSONYAML.load('{"something":"test","other":4}')=>{"something"=>"test","other"=>4}JSON将无法加载YAML。JSON.load("

  8. ruby - 如何在 ruby​​ 中运行后台线程? - 2

    我是ruby​​的新手,我认为重新构建一个我用C#编写的简单聊天程序是个好主意。我正在使用Ruby2.0.0MRI(Matz的Ruby实现)。问题是我想在服务器运行时为简单的服务器命令提供I/O。这是从示例中获取的服务器。我添加了使用gets()获取输入的命令方法。我希望此方法在后台作为线程运行,但该线程正在阻塞另一个线程。require'socket'#Getsocketsfromstdlibserver=TCPServer.open(2000)#Sockettolistenonport2000defcommandsx=1whilex==1exitProgram=gets.chomp

  9. ruby - 如何计算 Liquid 中的变量 +1 - 2

    我对如何计算通过{%assignvar=0%}赋值的变量加一完全感到困惑。这应该是最简单的任务。到目前为止,这是我尝试过的:{%assignamount=0%}{%forvariantinproduct.variants%}{%assignamount=amount+1%}{%endfor%}Amount:{{amount}}结果总是0。也许我忽略了一些明显的东西。也许有更好的方法。我想要存档的只是获取运行的迭代次数。 最佳答案 因为{{incrementamount}}将输出您的变量值并且不会影响{%assign%}定义的变量,我

  10. ruby - Rails 开发服务器、PDFKit 和多线程 - 2

    我有一个使用PDFKit呈现网页的pdf版本的Rails应用程序。我使用Thin作为开发服务器。问题是当我处于开发模式时。当我使用“bundleexecrailss”启动我的服务器并尝试呈现任何PDF时,整个过程会陷入僵局,因为当您呈现PDF时,会向服务器请求一些额外的资源,如图像和css,看起来只有一个线程.如何配置Rails开发服务器以运行多个工作线程?非常感谢。 最佳答案 我找到的最简单的解决方案是unicorn.geminstallunicorn创建一个unicorn.conf:worker_processes3然后使用它:

随机推荐