This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

Multi threading not working on RTX Kernel fro LPC1768

I am trying to configure RTX Kernel for LPC1768.
I use RTX help from "http://www.keil.com/support/man/docs/rlarm/rlarm_ar_create_newapp.htm"

In the help a file named RTX_Config.c is suggested (but it is not there at the suggested place) then I imported RTX_Conf_CM.c. Rest of the steps I have followed.

But still Only one execution thread is running.
here is structure of my code.

__task void CommandHandeler (void);
__task void init(void);
__task void MainThread(void);

__task void init(void)
{
        Print("Check 5.");
        os_tsk_create (MainThread, 2);
        Print("From thread 0");
        os_tsk_create (CommandHandeler, 1);

        while(1)
                os_dly_wait (5);
}

__task void MainThread(void)
{


        while(1)
        {
                delay(10000);
                Print("From thread 1.");
        }
}

__task void CommandHandeler(void)
{
        Action Act;
        while(1)
        {
                delay(20000);
                Print("From thread 2.");
        }

}

int main (void)
{
        SystemInit();
        SystemClockUpdate();
        UARTInit(0, 9600);      /* baud rate setting */
        os_sys_init(init);
}

This is the Output of that coded:
Check 5.
From thread 1.
From thread 1.
From thread 1.
: :

Rest of the print never comes.

Thanks in advance.

  • => But still Only one execution thread is running.

    os_tsk_create (MainThread, 2);
    

    MainThread has the highest priority always, so it runs always.

  • A question here is of course what "delay(20000);" does. It's a very large figure - 20,000 ms = 20 seconds? Or even finer granularity?

    Busy-loops are not so nice unless very short delays are needed (such as settle times for digital signals).

    The OS have a number of primitives that a thread can use to give up the access to the processor while waiting a fixed amount of time, or until something happens. This allows a high-priority thread to sleep while lower priority threads can step in and get some processing done.

    With a busyloop, a high-priority task will just run a high-priority busyloop wasting resources.

    It's normal to select a suitable tick frequency for the OS that works well with intended delays in the different threads. If something needs to be done at a finer granularity, then that is normally handled by a timer interrupt which can make use of ms or us time granularity.

  • Thanks for your reply,

    That delay() is just a loop to wast CPU cycle to generate some delay.
    But my problem is that, I am unable to make multiple execution pointer.

  • __task void init(void)
    {
            Print("Check 5.");
            os_tsk_create (MainThread, 1);
            Print("From thread 0");
            os_tsk_create (CommandHandeler, 1);
    
            while(1)
                    os_dly_wait (5);
    }
    

    change the priority of MainThread to 1, as the above shows, then see what will happen.

  • But you ignored the issue I was talking about.

    How long is your delay? Is it a busy loop? Can't it be modified to sleep the thread?

    It doesn't matter what thread priorities you use or if you get your threading to work or not. Busy-loops should be avoided whenever possible in a multithreaded system, unless we are talking about an "idle" thread that only runs when there is nothing else to do.

    If you have one thread with higher priority, and you let it busy-loop, then you will starve all other threads. A high-prio thread will only give CPU to less prioritized threads if it is helpful and calls any function that puts the thread to sleep while waiting for something.