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.

TI-RTOS 任务和线程的区别

Other Parts Discussed in Thread: CC2640R2F

我看到有些demo重使用了task,有些demo重使用了thread,请问这两种有什么区别呢? 还是说底层都是一样的东西

  • TI-RTOS里线程是一组在存储在存储器中的代码,一旦寄存器被正确初始化,CPU就会执行这些代码。

    线程可以是任何类型的,SYS/BIOS定义了四种线程类型:

    硬件中断(HWI),软件中断(SWI),任务(TASK),空闲(Idle)。

  • 我使用ccs导入一个cc2640r2f sdk里的empty项目后看到如下代码

    int main(void)
    {
        pthread_t           thread;
        pthread_attr_t      attrs;
        struct sched_param  priParam;
        int                 retc;
        int                 detachState;
    
        /* Call driver init functions */
        Board_initGeneral();
    
        /* Set priority and stack size attributes */
        pthread_attr_init(&attrs);
        priParam.sched_priority = 1;
    
        detachState = PTHREAD_CREATE_DETACHED;
        retc = pthread_attr_setdetachstate(&attrs, detachState);
        if (retc != 0) {
            /* pthread_attr_setdetachstate() failed */
            while (1);
        }
    
        pthread_attr_setschedparam(&attrs, &priParam);
    
        retc |= pthread_attr_setstacksize(&attrs, THREADSTACKSIZE);
        if (retc != 0) {
            /* pthread_attr_setstacksize() failed */
            while (1);
        }
    
        retc = pthread_create(&thread, &attrs, mainThread, NULL);
        if (retc != 0) {
            /* pthread_create() failed */
            while (1);
        }
    
        BIOS_start();
    
        return (0);
    }

    没有看到这个线程是什么类型的设置呢?

  • 楼主现在对这问题有进一步理解吗?