Sign In

Don't have a Xilinx account yet?

  • Choose to receive important news and product information
  • Gain access to special content
  • Personalize your web experience on Xilinx.com

Create Account

Username

Password

Forgot your password?
XClose Panel
Xilinx Home
Reply
Regular Visitor
munaq2005
Posts: 34
Registered: ‎11-18-2011
0

run thread in parallel

Hi all,

I have a problem in running several threads in parallel.

If one thread call a function with infinite loop, this prevent the next thread to be created or called its function.

below code, create 2 threads, if I create thread which calls non infinite loop it will work fine and create the thread 2 work

but if i create first the thread which calls infinte loop functions then the second function will not be called.

just revers order of lines which create 2 threads....

 

void* Func1(void * h)
{
xil_printf("\r\nFunc1\r\n");
    pthread_exit(NULL);
}
void* Func2(void * h)
{
xil_printf("\r\nFunc2\r\n");
while(true){
    //some code
}
    pthread_exit(NULL);
}
    int main()
    {
        xil_printf("Starting zChaff\n\r");
                    pthread_attr_t attr;
                    xilkernel_init();

                #if SCHED_TYPE == SCHED_PRIO
                    struct sched_param spar;
                #endif


                #if SCHED_TYPE == SCHED_PRIO
                    spar.sched_priority = PRIO_HIGHEST;
                    pthread_attr_setschedparam(&attr, &spar);
                #endif

                pthread_attr_init (&attr);
               pthread_attr_setschedparam(&attr, PTHREAD_CREATE_DETACHED);
                pthread_t th1,th2;
                pthread_create (&th1, &attr, Func2,NULL);
                pthread_create (&th2, &attr, Func1,NULL);

   xilkernel_start();
        while(1)
        {

        }

}

 

thanks

Regular Visitor
munaq2005
Posts: 34
Registered: ‎11-18-2011
0

Re: run thread in parallel

comment above if clauses, has no effect

use default attribute is the same

put a break sentence or a condition breaks the infinite loop, terminate the first and call the second..

Super Contributor
joy1887
Posts: 148
Registered: ‎03-31-2011
0

Re: run thread in parallel

[ Edited ]

yes thats true as xilkernel supports strict pririty schedule u can't run two thread in  parallel in this way it will be concurrent in nature..if the while loop thread has the higher prioriuty then it will not handover the control to other..u can use SCHED_RR

and can include features like semaphore and mutex for thread sysnchronization,,what exactly u want to do by two threads..but here seems that  u have assigned same priority to both the tharads then the scheduling will be RR..what is your pthread static function?

 

regards

Regular Visitor
munaq2005
Posts: 34
Registered: ‎11-18-2011
0

Re: run thread in parallel

thanks for your reply,

 

I want to have a thread running always , it reads timer1 and check if it recieves overflow

I want to calculate the speed of an algorithm, so this thread must start first.

Other threads run differnt algorithm...

I have to calculate the run speed for every thread- run time...

I tried sched_RR , it doesn't run in a good way...

Super Contributor
joy1887
Posts: 148
Registered: ‎03-31-2011
0

Re: run thread in parallel

I think u have to modify your design scennario,because in xilkernel threads are coded like functions, but can work not truely in parallel, however, unless you have multiple processors. In a single processor, parts of the function/thread are processed in a scheduled fashion, very quickly -- giving the the impression that they are being processed in parallel in realtime.

 

 

Regular Visitor
munaq2005
Posts: 34
Registered: ‎11-18-2011
0

Re: run thread in parallel

thanks alot, I will modify my design ..

I tried sched_RR , it may better than sched_PRIO, in particular if one thread work in infinite loop

But i can't use it in my application...

 

thanks again