- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic to the Top
- Bookmark
- Subscribe
- Printer Friendly Page
run thread in parallel
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
05-26-2012 12:13 PM
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
Re: run thread in parallel
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
05-26-2012 08:39 PM
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..
Re: run thread in parallel
[ Edited ]- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
05-26-2012 11:58 PM - edited 05-27-2012 12:34 AM
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
Re: run thread in parallel
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
05-27-2012 11:11 AM
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...
Re: run thread in parallel
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
05-27-2012 11:37 AM
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.
Re: run thread in parallel
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
05-28-2012 06:39 AM
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











