开发者

vxWorks pthreads

开发者 https://www.devze.com 2023-04-13 01:52 出处:网络
All the docume开发者_开发知识库ntation 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 expecte

All the docume开发者_开发知识库ntation 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?


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'


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消