vxWorks pthreads

发布于 2024-12-09 14:55:37 字数 1002 浏览 1 评论 0原文

到目前为止我读过的所有文档似乎都表明我的 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

半枫 2024-12-16 14:55:37

假设您使用 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'

枫林﹌晚霞¤ 2024-12-16 14:55:37

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文