- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我已经在我的 ubuntu 机器上克隆并构建了 riscv-tools 存储库。 Hello world 程序运行良好。
现在,我正在尝试将应用程序从 X86 目标移植到 riscv (RV32IM) 目标。我的应用程序依赖于数学和 pthread 库。尝试在我的代码中使用 pthread.h 头文件中的声明时遇到问题。
我做了一个非常简单的示例代码来演示我的问题。
这是我的example.c文件内容
#include <stdio.h>
#include <math.h>
#include <pthread.h>
int main(void)
{
float my_float;
int rc;
pthread_t my_thread;
pthread_mutex_t my_lock;
printf("Example start!\n");
my_float = sqrt( 16.0 );
printf("sqrt(16.0) = %f\n", my_float);
rc = pthread_mutex_init(&my_lock, NULL);
printf("return code from pthread_mutex_init() is %d\n", rc);
printf("Example End!\n");
return 0;
}
好的,这是我为 RISCV 目标编译它的命令行
riscv64-unknown-elf-gcc -Wall -m32 -march=RV32IM -o example example.c -lm -lpthread
这是编译器的输出:
example.c: In function 'main':
example.c:10:3: error: unknown type name 'pthread_t'
pthread_t my_thread;
^
example.c:11:3: error: unknown type name 'pthread_mutex_t'
pthread_mutex_t my_lock;
^
example.c:19:3: warning: implicit declaration of function 'pthread_mutex_init' [-Wimplicit-function-declaration]
rc = pthread_mutex_init(&my_lock, NULL);
^
example.c:10:13: warning: unused variable 'my_thread' [-Wunused-variable]
pthread_t my_thread;
^
请注意,数学库没有问题,但 pthread 库会产生错误。
显然,为 X86 目标编译这个简单的示例非常有效。 X86 目标的程序输出是:
> ./example
Example start!
sqrt(16.0) = 4.000000
return code from pthread_mutex_init() is 0
Example End!
这是我们在执行此操作时在 RISCV 目标上编译和运行时最终应该得到的:
spike pk ./example
RISCV 工具链中的 pthread 库有什么问题?RISCV 社区的任何人都可以重现它吗?有人遇到同样的问题吗?
感谢任何帮助!
最佳答案
对于多线程应用程序,您需要升级到 linux 编译器和内核。代理内核 (pk) 在其运行的用户程序中不支持多线程。此外,我们还没有设置基于 newlib 的编译器来支持 pthreads。
步骤
关于riscv - RISCV 工具链是否支持 pthread 库?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31595277/
我正在将一些 pthreads 代码添加到我使用 autotools 构建的 Linux 应用程序中。我收到关于未在 libpthreads 中链接的错误。所以我想在 autotools 中指定 pt
libpthread 库位于 Linux 系统的哪个目录中? 最佳答案 有多种方法可以找出这一点。 只需输入 find / -name 'libpthread.so' -print找到名为 libpt
pthread 属性对象是否需要在使用它们的对象的生命周期内存在,或者在使用它们后立即销毁它们是否安全?例如: // Create the mutex attributes. pthread_mute
到目前为止我读过的所有文档似乎都表明我的 vxWorks (6.8) 版本中存在 posix 线程支持,但是一个简单的测试应用程序无法按预期执行。来源如下: tTest.h #include cla
我试图找到指定 pthreads 标准的文档。我见过各种指向 IEEE 1003.1c-1995 的链接(即 Wikipedia 或 OpenGroup )。然而,当我在 IEEE 标准站点上搜索此文
我试图找到指定 pthreads 标准的文档。我见过各种指向 IEEE 1003.1c-1995 的链接(即 Wikipedia 或 OpenGroup )。然而,当我在 IEEE 标准站点上搜索此文
我在 MSVC 2010 上运行一个 pthread,我已经包含 pthreadVC2 .lib & .dll。来自以下网站 http://sourceware.org/pthreads-win32/
我的问题是: 如何在不更改其他 pthread 中的当前目录的情况下更改 pthread 中的当前目录,我找到了一个使用 openat() 函数的解决方案,但我没有找到任何解释它如何工作的示例。 使用
是否可以通过任何方式更改进程可以创建的 pthread 数量限制? 目前在我的 linux 系统上我可以创建大约 380 个线程,但我想增加它,只要内存可用。 最佳答案 减少用户的堆栈大小' ulim
问候。我正在尝试创建一个 autoconf 配置脚本,该脚本自动检查要使用的 pthread 选项,并且理想情况下,在使用 gcc 编译时指定 -pthread。 我希望 AX_PTHREAD 能够工
如何知道 pthread 是否死亡? 有办法检查 pthread 状态吗? 最佳答案 if(pthread_kill(the_thread, 0) == 0) { /* still runni
我正在从一个由互斥锁控制的固定大小的全局池中分配我的 pthread 线程特定数据。 (有问题的代码不允许动态分配内存;它允许使用的所有内存都由调用者作为单个缓冲区提供。pthreads 可能会分配内
在阅读了一些 MPI 规范后,我了解到,当使用 MPI_THREAD_SERIALIZED 进行初始化时,程序必须确保发生在不同线程中的 MPI_Send/Recv 调用不能重叠。换句话说,您需要一个
我尝试根据 this guide 安装 pthread win32 . 我将 pthreadVC2.dll 文件添加到 C:\Windows 并将 pthreadVC2.lib 文件添加到 C:\Pr
我有一个 pthreads 程序。我必须使用 Linux 中的 gcc -pthread(-pthreads 是无法识别的选项)和 Sun 中的 gcc -pthreads(-pthread 是无法识
我有一个包含文件名列表的文件,我想在其中搜索一个词并替换它我稍微修改了代码只是为了在这里只显示相关部分问题是如果我在该列表中只有一个文件,它不会用多线程处理它,因为线程只有在我有多个文件时才工作所以我
我正在编写一个 SMT 程序,并且正在尝试解决一个有趣的问题。 我需要所有函数一起退出,但是有些线程卡在障碍物上,即使我不希望它们这样做。 我的问题是:当我删除障碍时会发生什么?卡在屏障处的线程会释放
我阅读了有关 pthread 及其相关 API 的所有内容,以创建、锁定和同步不同的线程。但我经常发现线程池、消费者/生产者等词提示。我理解这些是 pthread 实现的模型。 任何人都可以让我知道
我在 man pthread_join 中读到,多个 pthread 不能加入一个已经加入的 pthread。还有另一种方法可以达到相同的结果吗?多个 pthread 挂起自己,直到某个特定的 pth
我知道 OpenMP 实际上只是一组编译成 pthread 的宏。有没有办法在编译的其余部分发生之前查看 pthread 代码?我正在使用 GCC 进行编译。 最佳答案 首先,OpenMP 不是一组简
我是一名优秀的程序员,十分优秀!