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.

using Task

Hi

I set "Image_proc_omp" demo project as my base project.  I want to use multi thread programming so I made and added two thread dynamically as below.

Question 1:

Is it necessary to use Task_delet() function? if the answer is yes where should I use it? 

Question 2:

Is my thread creation method correct?

When I changed the priority of "master_main" thread to any number (2 until 15) except number 5, an error occurred as below:

Question 3:

Why the master_main thread works only by priority 5?

Question 4:

How should I set priority to threads?

I mean I don't uderstand the relation and quality between periyirity number of threads for example in visual studio you

can set the priority low, high or real time but here I don't have any sense between thread priority number. 

Question 5:

What should I do for synchronization between thread?

At first I tried to synchronize threads by declared some flags but it didn't work as I wanted. Should I use semaphore or event module?

Best Regards

  • Hi

    I am waiting, Please answer me.

  • Dariush,

    I apologize for the delay. I thought someone from another group would reply.

    I'm not very familiar with MCSDK, nor any of the examples that are provided with it.

    What conditions cause the "Illegal priority call..." message to be generated? I see the two new Task_create() calls, but 4 "Illegal priority call.." messages are being generated.

    Can you share the .cfg file and C source files the application is built with?

    Alan
  • Dariush,

    Actually, since this issue seems to be specific to MCSDK and not TI-RTOS per se, I went ahead and moved it over to the device forum, as I think it will get a faster and more comprehensive response there.
  • The "Illegal priority.." messages are probably not coming from the Task_create() code. They are due to something the created task functions are doing. Can you share the task function code? A colleague of mine pointed out that the messages are coming from the llEnter() function within the NDK's ostask.c file. Apparently, user task priorities must be less than OS_TASKPRIKERN which defaults to 6. But you say that you have the problem even with priorities 2-4. I suggest studying the NDK documentation to see what the restrictions are for user task priorities.

    In answer to question 5, a semaphore is often used to synchronize threads. One semaphore shared by the two tasks may be enough: one task blocks until the other task posts the semaphore, then the posting task blocks on the same semaphore until the first task finishes processing and posts the semaphore, etc...

    Alan
  • Regarding question #1, do the tasks you are creating eventually finish their work and fall through the bottom of the task function? And do they subsequently get re-created later on? If so, then to avoid eventually running out of heap memory, you'll need to delete them after they've terminated. If the tasks never fall through the bottom of their task function then there is no need to delete them. If you can structure the task functions to simply block until they are needed, then perhaps you can avoid the need to create and delete them periodically.
  • Hi Alan

    Thank you very much, in "C:\ti\bios_6_33_06_50\docs\Bios_User_Guide.pdf " document at page 113 explains about event modules that provide a means for communicating between and synchronizing threads.

    Question 1:

    Which one should I focus on?(event module or semaphore)

    I want the "master_main" task to receive data permanently and "PreProcess" task to parse the receiving packets and save them in DDR3 memory and finally "Sig_Proc" task read and process the data from DDR3 memory. So I should put the highest priority for "master_main" and other tasks should have lower priority. I attach for you .cfg and .c files. However, as I mentioned before, I didn't understand how to set the priorities.

    Question 2:

    How should I set and manage the priorities?

    Source.rar

    image_processing_openmp_evmc6678l.cfg

    Question 3:

    Is it necessary to set some settings in project properties for describing " inline " functions?

    Best Regards

  • I think 3 counting semaphores would be the lightest weight solution for synchronizing your tasks.

    At start up, all three tasks pend on their respective semaphore, (call them sem1, sem2, sem3).

    1) When an interrupt comes in that collects the next message, the ISR function posts sem1, which master_main() is blocked on.

    2) master_main() then returns from Semaphore_pend() and performs whatever processing is required to allow PreProcess to begin its work, then it posts sem2 which PreProcess is blocked on. master_main then blocks on sem1 again, waiting for the ISR.

    3) PreProcess then returns from Semaphore_pend() and performs its work, copies the message to DDR3, posts sem3, which Sig_Proc is blocked on, then PreProcess again blocks on sem2.

    4) Sig_Proc then returns from Semaphore_pend(), does whatever it needs to do, then block again on sem3.

    I'm still unclear as to why you can't set a task priority to anything but 5.

    I don't understand your question regarding "inline" functions.

    Alan
  • Hi Alan

    About "can't set a task priority to anything but 5" problem I studied spru523h.pdf, in page 74 it explained about such a problem, but my problem solved without doing any special work!! and now I can set the priority to any number!!!!.

    About "inline" function, in Visual Studio when declared inline function in "project properties\ configuration...\ (c\c++) \  optimisation \ inline expression... "

    we can set it to Ob1, Ob2... .

    Question 1:

    Is there same settings in CCS?

    I appreciate you for your guidance about using semaphore. 

    Question 2:

     Can we solve the synchronization thread problem by time scheduling (using tasksleep())?

    Regards

  • I am very glad to hear that you got past the task priority issue.

    1) I refer you to the compiler user manual regarding how the "inline" function attribute is treated. Here is my understanding: In order for the 'inline' function attribute to take affect, you must set the optimization level to "--opt_level=3". However, this only "allows" the compiler to use its best judgment about whether to actually inline the code. If the function is large and invoked many times, the compile may still decide that it makes more sense to create one copy and call it as a subroutine.

    2) Task_sleep() only puts a task in a blocked state for a fixed number of Clock ticks. It does not synchronize program execution between several tasks.
  • I used task_sleep() before for synchronization. I had three task (high,medium,low) when the fist task executed task_sleep() it blocked and the medium task ran until the time that set in the task_sleep() function, spent. Next time when high task received to the task_sleep() again, low task execute but in that case the rate was low and that method worked.

    Now I want high task (master_main) receives data real time and permanently, the medium task (preprocess) parses the packets real time permanently, after 2 seconds the low task (sig_proc) starts to process the data and this pipeline works permanently. The high and medium task never stop, they should only synchronize together to avoid conflict.

    (In current project all tasks start at same time according to they have different priority, it is strange!!!??)

    Question 1:

    How I config semaphore mode? (binary or counting)

    I copied the configuration parameter to my source file but it produced error!! (undeclared) I added it's header file to my source file and added it,s package in

  • If you have 3 ready tasks of different priority: 3, 2, 1, then the priority 3 task will run first until it blocks, then the priority 2 task will run until it blocks or is pre-empted by 3, then the priority 1 task will run until it blocks or gets pre-empted by 3 or 2.

    1) The documentation regarding the 'mode' configuration parameter is a little confusing. 'mode' is one of the instance configuration parameters within the Semaphore_Params structure you pass to Semaphore_create():

    Semaphore_Params semParams;

    Semaphore_Params_init(&semParams);

    semParams.mode = Semaphore_Mode_COUNTING;
    mySem = Semaphore_create(0, &semParams, NULL); /* create a counting semaphore with initial count of zero */.

    Alan
  • Hi Alan

    My problem about task synchronization solved, Thank you very much.

    When my EVM board connected to network an error occurred and some sentences printed in the console as below:

    00002.887 PBM_free: Invalid Packet

    00002.888 PBM_enq: Invalid Packet 

    Service Status: HTTP            :Disable:                    :000

    What is the problem? what should I do?

    Regards

  • I see that you have posted this latest issue as a new thread and that you are being helped.
    Please mark this thread answered if you feel that your original issues were resolved satisfactorily.

    Alan
  • Dear Alan

    I have a new problem please help me.

    Question 1:

    How can I use OpenMP in task function?

    when I use OpenMP out of task function, it works but when i use it in " sig_proc" task function it doesn't work.

    Thank you

  • Dariush,

    If this indeed a new problem, then you should post it to a new thread. This will make it more likely that the right person will see your question, rather than just the person who happened to answer previously. In addition, it will the question and answer to be more easily searched by other customers who may have a similar issue.
  • David

    I created a new thread, please answer me.

    My new thread: e2e.ti.com/.../475956

    Thank You