Hi,guys.
   I write nether program with gnu pth,I find that scheduler of thread can't
work well,and last Just ninth thread working.Someone can help me?
 Very Thanks.

#include <stdlib.h>
#include <stdio.h>
#include <pth.h>

void* ticker(void *s)
{
 int i;
 for(i=0;;i++)
 {
 printf("%s__%i\n",(char*)s,i);
 pth_usleep(100000);
 }
}
int main(int argc,char argv[][])
{
 pth_attr_t attr[10];
 int i;
 pth_t pth[10];
 char str[80];
 pth_init();
 for(i=0;i<10;i++)
 {
  attr[i] = pth_attr_new();
  sprintf(str,"ticker %d",i);
  pth_attr_set(attr[i],PTH_ATTR_NAME,str);
  pth_attr_set(attr[i],PTH_ATTR_STACK_SIZE,80*1024);
  pth_attr_set(attr[i],PTH_ATTR_JOINABLE,FALSE);
  pth[i] = pth_spawn(attr[i],ticker,(void *)str);
  pth_usleep(100000);
 }
 while(1) pth_sleep(1);

}

/*Result of the program running*/
ticker 0__0
ticker 1__0
ticker 1__1
ticker 2__0
ticker 2__1
ticker 2__2
ticker 3__0
ticker 3__1
ticker 3__2
ticker 3__3
ticker 4__0
ticker 4__1
ticker 4__2
ticker 4__3
ticker 4__4
ticker 5__0
ticker 5__1
ticker 5__2
ticker 5__3
ticker 5__4
ticker 5__5
ticker 6__0
ticker 6__1
ticker 6__2
ticker 6__3
ticker 6__4
ticker 6__5
ticker 6__6
ticker 7__0
ticker 7__1
ticker 7__2
ticker 7__3
ticker 7__4
ticker 7__5
ticker 7__6
ticker 7__7
ticker 8__0
ticker 8__1
ticker 8__2
ticker 8__3
ticker 8__4
ticker 8__5
ticker 8__6
ticker 8__7
ticker 8__8
ticker 9__0
ticker 9__1
ticker 9__2
ticker 9__3
ticker 9__4
ticker 9__5
ticker 9__6
ticker 9__7
ticker 9__8
ticker 9__9
ticker 9__1
ticker 9__2
ticker 9__3
ticker 9__4
ticker 9__5
ticker 9__6
ticker 9__7
ticker 9__8
ticker 9__9
ticker 9__10


--
 -------- __@      __@       __@       __@      __~@
 ----- _`\<,_    _`\<,_    _`\<,_     _`\<,_    _`\<,_
 ---- (*)/ (*)  (*)/ (*)  (*)/ (*)  (*)/ (*)  (*)/ (*)
 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Email [EMAIL PROTECTED] MSN:[EMAIL PROTECTED]  ICQ:89646944


______________________________________________________________________
GNU Portable Threads (Pth)            http://www.gnu.org/software/pth/
User Support Mailing List                            [EMAIL PROTECTED]
Automated List Manager (Majordomo)           [EMAIL PROTECTED]

Reply via email to