This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

RTOS: about multithread in CCS

Other Parts Discussed in Thread: SYSBIOS

Tool/software: TI-RTOS

HI i'm trying to use multithread in CCS, but  i can't find how do i do.

#include <ti/sysbios/posix/pthread.h>
#include <stdlib.h>
#include <xdc/std.h>
#include <xdc/runtime/System.h>

#include <ti/sysbios/BIOS.h>
#include <ti/sysbios/knl/Task.h>

/* Drivers */
#include <ti/drivers/rf/RF.h>
#include <ti/drivers/PIN.h>

/* Board Header files */
#include "Board.h"

#include "smartrf_settings/smartrf_settings.h"

#include <xdc/std.h>


#include <ti/sysbios/knl/Clock.h>
#include <ti/sysbios/knl/Task.h>
#include <ti/sysbios/posix/unistd.h>
#include <ti/sysbios/posix/Settings.h>
#include <ti/sysbios/posix/types.h>


static Task_Params taskParams;
static pthread_attr_t   *pAttr;

/* This is our thread function.  It is like main(), but for a thread*/
void *threadFunc(void *arg)
{
    char *str;
    int i = 0;

    str=(char*)arg;

    while(i < 10)
    {
        usleep(1000*1000);
        System_printf("threadFunc says: %s\n",str);
        i++;
    }

    return 0;
}

int main(void)
{
    pthread_t pth;  // this is our thread identifier
    int i = 0;

    Task_Params_init(&taskParams);
    taskParams.priority = pAttr->priority;
    taskParams.stack = pAttr->stack;
    taskParams.stackSize = pAttr->stacksize + pAttr->guardsize;
    pthread_create(&pth,NULL,threadFunc,"foo");

    while(i < 10)
    {
        usleep(1000*1000);
        System_printf("main is running...\n");
        i++;

    }

    System_printf("main waiting for thread to terminate...\n");

    pthread_join(pth,NULL);
    BIOS_start();
    return 0;
}

this is my main code

and it doesn't work

how can i do?

if you know how can i fix the code, let me know plz :-)

  • Can you give more details? What does not work?
  • Hi ToddMullanix!

    Thank you really about your reply.

    I got your reply and changed my code but it doesn't display on console

    i find the Systed so i change Sydcallback to Syssted on the .cfg

    also add the code for using pthread on the .cfg



    but it doesn't work

    i think the output will alternate the trheadFunc, threadFunc1, and the main while() results on the console

    this is my new code

    /***** Includes *****/
    #include <stdlib.h>
    #include <xdc/std.h>
    #include <xdc/runtime/System.h>

    #include <ti/sysbios/BIOS.h>
    #include <ti/sysbios/knl/Task.h>
    #include <ti/sysbios/knl/Clock.h>
    #include <ti/sysbios/posix/unistd.h>
    /* Drivers */
    //#include <ti/drivers/rf/RF.h>
    #include <ti/drivers/PIN.h>

    /* Board Header files */
    #include "Board.h"

    //#include "smartrf_settings/smartrf_settings.h"
    #include <ti/sysbios/posix/pthread.h>



    /* This is our thread function. It is like main(), but for a thread*/
    void *threadFunc(void *arg)
    {
    char *str;


    str=(char*)arg;

    while(1 )
    {
    usleep(1000000);
    System_printf("threadFunc says: \n");
    }


    return NULL;
    }
    void *threadFunc2(void *arg)
    {
    char *str;


    str=(char*)arg;

    while(1 )
    {
    usleep(1000000);
    System_printf("threadFunc2 says:\n");
    }
    return NULL;
    }

    int main(void)
    {
    pthread_t pth,pth2; // this is our thread identifier
    int i = 0;

    pthread_create(&pth,NULL,threadFunc,NULL);
    pthread_create(&pth2,NULL,threadFunc2,NULL);

    while(1)
    {

    usleep(1000);
    System_printf("main is running...\n");
    ++i;

    }

    System_printf("main waiting for thread to terminate...\n");
    //pthread_join(pth,NULL);

    BIOS_start();

    return 0;
    }

    and then i'm sorry for asking you about this request........

    could you give me a sample multithreading code...?

    or let me know what's wrong with my code..
  • Which device are you on? I'm going to assume you are on a SimpleLink device. There are numerous examples in SimpleLink SDK. I'd import the demos/portable example. It has a couple threads. Please refer to the Quick Start to see how to import/build/run an example.

    Todd