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.

Compiler/66AK2H14: Multi-threading in CCS

Part Number: 66AK2H14
Other Parts Discussed in Thread: 66AK2H12, SYSBIOS,

Tool/software: TI C/C++ Compiler

Hi,

I am using CCS7.4.

I am trying to use both the hyperlink ports[Hyplnk0 and Hyplnk1] at once as in this post.

I thought of creating two threads and configuring each port though the threads.

I referred this wiki for creating threads .

1. one thread is created successfully but for second thread it was giving ENOMEM error.

How to solve this error?

2.I commented the second thread and tried with only one thread.

I was getting error for pthread_join as

  • EINVAL – pthread_join() was called on a thread that another thread has already called pthread_join() on the thread.

Please help me to solve these errors.

Regards,

Mahima Shanbag

  • Hi,
    This is how I created threads in my application.
    int main(void)
    {
    // , *dataBufPtr_1;
    Board_initCfg boardCfg;
    int threadArg = 1;
    pthread_attr_t attr;
    boardCfg = BOARD_INIT_PINMUX_CONFIG |
    BOARD_INIT_MODULE_CLOCK |
    BOARD_INIT_UART_STDIO;
    Board_init(boardCfg);

    pthread_attr_init(&attr);
    pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_JOINABLE);
    if(pthread_create(&port0_thread, &attr , (ThreadFxn)hyplnk_port0, (void *)threadArg))
    {
    UART_printf("Error creating thread\n");
    return 1;

    }
    if(pthread_create(&port1_thread, &attr,(ThreadFxn) hyplnk_port1 ,(void *)threadArg))
    {
    UART_printf("Error creating thread\n");
    return 1;
    }


    pthread_join(port0_thread,NULL);
    pthread_join(port1_thread,NULL);
    return 0;


    }
    Please help me to solve this issue.

    Regards,
    Mahima Shanbag
  • Hi,

    I wonder if this issue is generic to thread creation or particular to hyperlink. In another word, if you replace thread function hyplnk_port0() and hyplnk_port1() with something simple like "hello world", do you still error?

    Regards, Eric
  • Hi Eric,
    I replaced hyplnk_port0() and hyplnk_port1() with hello world, but still the result was same.
    I was not able to create 2 threads.

    I tried the same in hello_66AK2H12_C66XX project, here I was able to create two threads.
    But for pthread_join I was getting below assertion:
    ti.sysbios.knl.Semaphore: line 202: assertion failure: A_badContext: bad calling context. Must be called from a Task.

    Please help me to solve this.
    Regards
    Mahima Shanbag
  • Mihima,

    For the thread creation issue, can you confirm what size of heap you have? Look in Tools->ROV->HeapMem to see the size and current free space. I expect the heap is too small and when the create tries to allocate stack space, it gives the error. Note: you can supply the stack to avoid the allocation in the create.

    To increase the RTOS' heap, adjust the following in the .cfg accordingly.
    BIOS.heapSize = 65536;

    (I'm assuming you are not doing the HeapMem.primaryHeapBaseAddr, etc. trick in the .cfg file. If you are, increase the HEAPSIZE constant in your linker file).

    Todd
  • Hi Todd,
    Thank you for your support.
    Now I am able to create 2 threads in Hyplnk application But for pthread_join still I am getting below assertion:
    ti.sysbios.knl.Semaphore: line 202: assertion failure: A_badContext: bad calling context. Must be called from a Task.

    Please help me to solve this.

    Regards,
    Mahima Shanbag
  • Hi Mahima,

    You are calling a Semaphore_pend from a Swi or Hwi with a non-zero timeout and the semaphore is not available. The easiest way to find this is to open a disassembly window and enter "xdc_runtime_Error_raiseX__E" into the window. Then set a breakpoint at the beginning of the function. Run the app and when the breakpoint is hit, look at the Debug callstack.

    Todd

  • Hi Todd,

    I looked into the debug call stack , I didnt see any SWI and HWI thread calling  Semaphore_pend().

    I have attached the screenshot here.

    Thanks and Regards,

    Mahima Shanbag

  • Hi Mahima,

    You cannot call pthread_join from main()

    Please look at this page for more details: processors.wiki.ti.com/.../BIOS_POSIX_Thread_(pthread)_Support . Specifically at
    "For example, pthread_create() can be called from main(), but pthread_join() cannot. " and the "Summary of Pthread APIs supported in SYS/BIOS" near the end of the page.

    Todd
  • Hi Todd,
    Whether SMP(symmetric multiprocessing) is supported in 66AK2H14.
    Because When I create two threads , those threads were not running simultaneously.
    In my project I have to make both the threads work simultaneously.
    Please help me with this.

    Thanks and Regards,
    Mahima Shanbag
  • This looks like a new question. Can you please open a new thread for this?

    Todd