vxWorks pthreads
到目前为止我读过的所有文档似乎都表明我的 vxWorks 版本(6.8)中存在 posix 线程支持,但是一个简单的测试应用程序无法按预期执行。源代码如下:
tTest.h
#include <pthread.h>
class tTest
{
public:
tTest();
virtual ~tTest();
private:
pthread_t tid;
static void* Worker(void* args);
};
tTest.cpp
#include <stdio.h>
#include "tTest.h"
tTest::tTest()
{
printf("Starting up...\n");
if(pthread_create(&tid, NULL, &tTest::Worker, NULL))
{
printf("Failed to create thread.\n");
}
}
tTest::~tTest()
{
if(pthread_join(tid,NULL))
{
printf("Failed to join thread.\n");
}
printf("Shutting down...\n");
}
void* tTest::Worker(void* args)
{
printf("ThreadID: %d\n", (int)pthread_self());
return NULL;
}
vxWorks 内核模块的入口点很简单:
#include "tTest.h"
int tTest_main()
{
tTest m;
return 0;
}
启动/关闭消息很好,但工作线程却不好。这在 Linux 中工作得很好并且符合预期。我缺少什么?
All the documentation I've read so far seems to indicate that posix thread support exists in my version of vxWorks (6.8) however a simple test application fails to perform as expected. Here's the source:
tTest.h
#include <pthread.h>
class tTest
{
public:
tTest();
virtual ~tTest();
private:
pthread_t tid;
static void* Worker(void* args);
};
tTest.cpp
#include <stdio.h>
#include "tTest.h"
tTest::tTest()
{
printf("Starting up...\n");
if(pthread_create(&tid, NULL, &tTest::Worker, NULL))
{
printf("Failed to create thread.\n");
}
}
tTest::~tTest()
{
if(pthread_join(tid,NULL))
{
printf("Failed to join thread.\n");
}
printf("Shutting down...\n");
}
void* tTest::Worker(void* args)
{
printf("ThreadID: %d\n", (int)pthread_self());
return NULL;
}
The entrypoint for the vxWorks kernel module is simply:
#include "tTest.h"
int tTest_main()
{
tTest m;
return 0;
}
The startup/shutdown messages are good, but the worker thread is not. This works fine and as expected in linux. What am I missing?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
假设您使用 WindRiver Workbench 来开发此应用程序,您将需要使用内核配置并启用 POSIX 线程包。
这可以通过在内核配置中搜索“pthreads”来完成
Assuming you are using the WindRiver Workbench to develop this application, you will need to use the kernel configuration and enable the POSIX threads package.
This can be done by performing a search on the kernel configuration for 'pthreads'
VxWorks 6.8 中存在 POSIX 支持,但大多数 POSIX 组件不包含在默认配置中。在工作台中,POSIX 支持在内核配置的 POSIX Components 文件夹下启用。
POSIX 支持分为许多不同的模块,例如进程调度、时钟(默认包含)、消息队列等。
如果您在工作台下进行开发,则包括适当的组件(在本例中为 INCLUDE_POSIX_THREADS)还将包括任何其他模块pthreads 所依赖的组件。如果您在工作台之外配置内核,则需要确保手动包含所有依赖项。
POSIX support exists in VxWorks 6.8, but most POSIX components are not included in the default configuration. In workbench POSIX support is enabled under the POSIX Components folder of the kernel configuration.
POSIX support is broken up into a number of different modules, e.g. process scheduling, clocks (included by default), message queues, etc.
If you are developing under workbench, including the appropriate component (in this case INCLUDE_POSIX_THREADS) will also include any other components which pthreads depend on. If you are configuring a kernel outside of workbench, you will need to ensure you include all dependencies manually.