Home Articles News Work in progress...
Work in progress...
User Rating: / 2
PoorBest 
Written by Freddie Chopin   
Friday, 29 August 2014 19:37

I was thinking about doing something like that for a long time... However usually intent is far away from something concrete, especially when you don't have that much free time in your hands. Finally I pulled myself together, so here is a little "teaser" of what I'm currently working on (among other things).

bool ThreadFunctionTypesTestCase::run_() const
{
    using scheduler::makeStaticThread;

    // thread with regular function
    {
        uint32_t sharedVariable {};
        constexpr uint32_t magicValue {0x394e3bae};

        auto regularFunctionThread = makeStaticThread<testThreadStackSize>(UINT8_MAX,
                regularFunction, std::ref(sharedVariable), magicValue);
        regularFunctionThread.start();
        regularFunctionThread.join();

        if (sharedVariable != magicValue)
            return false;
    }

    // thread with state-less functor
    {
        uint32_t sharedVariable {};
        constexpr uint32_t magicValue {0x2c2b7c30};

        auto functorThread = makeStaticThread<testThreadStackSize>(UINT8_MAX, Functor{},
                std::ref(sharedVariable), magicValue);
        functorThread.start();
        functorThread.join();

        if (sharedVariable != magicValue)
            return false;
    }

    // thread with member function of object with state
    {
        constexpr uint32_t magicValue {0x33698f0a};
        Object object {magicValue};

        auto objectThread = makeStaticThread<testThreadStackSize>(UINT8_MAX,
                &Object::function, std::ref(object));
        objectThread.start();
        objectThread.join();

        if (object.getVariable() != magicValue)
            return false;
    }

    // thread with capturing lambda
    {
        uint32_t sharedVariable {};
        constexpr uint32_t magicValue {0x24331acb};

        auto capturingLambdaThread = makeStaticThread<testThreadStackSize>(UINT8_MAX,
                [&sharedVariable, magicValue]()
                {
                    sharedVariable = magicValue;
                });
        capturingLambdaThread.start();
        capturingLambdaThread.join();

        if (sharedVariable != magicValue)
            return false;
    }

    return true;
}

Intriguing? Curious? Interesting? (;

It's a fragment of functional tests of an open-source project, which currently is in early alpha stage (first line of code was written just last month), but basic things - like the ones shown in the piece of code above - are working (on STM32F4) pretty well (; There is not much to say now, the only trace of this project is the github repository and this news... Just like in any open-source project the most important things are the users and the community, so any thoughts, ideas, remarks, opinions etc. can be posted here - in comments - or on github. If anyone's up for some coding, I'm open to cooperation. Work is ongoing, so "stay tuned" (;

Complete source file from which the fragment above was taken can be seen under this link.

Last Updated on Sunday, 22 March 2015 21:18