All of lore.kernel.org
 help / color / mirror / Atom feed
* [Xenomai-help] Problem API Posix : ressource temporarily unavailable
@ 2007-05-23 13:49 Perrine Martignoni
  2007-05-23 13:59 ` Gilles Chanteperdrix
  0 siblings, 1 reply; 2+ messages in thread
From: Perrine Martignoni @ 2007-05-23 13:49 UTC (permalink / raw)
  To: xenomai

[-- Attachment #1: Type: text/plain, Size: 1973 bytes --]

Hello,

I work on an ARM9 with the API Posix and I found a problem during my tests.
I have written a simple example who show this problem.
Here is my code :

#include <pthread.h>
#include <string.h>
#include <stdio.h>
#include <signal.h>
#include <time.h>
#include <errno.h>
#include <fcntl.h>
#include <getopt.h>
#include <unistd.h>
#include <stdlib.h>
#include <sys/mman.h>
#include <sys/time.h>
#include <limits.h>
#include <mqueue.h>
void routine (void * cookie);
void routine (void * cookie)
{
struct timespec timeout;
struct sched_param param = {.sched_priority = 10 };
pthread_setschedparam(pthread_self(), SCHED_FIFO, &param);
timeout.tv_sec=0;
timeout.tv_nsec=200000000;

nanosleep ( &timeout, NULL);
printf("destruction tache\n");
pthread_exit(NULL);
}

int main(int argc, char **argv)
{
int i = 0;
int err;
pthread_attr_t attr;
pthread_t task;
struct timespec timeout, timeout2;
struct sched_param param = {.sched_priority = 10 };

mlockall(MCL_CURRENT | MCL_FUTURE);

timeout.tv_sec=50;
timeout.tv_nsec=0;
timeout2.tv_sec=0;
timeout2.tv_nsec=500000000;

pthread_attr_init(&attr);
pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_JOINABLE);
pthread_attr_setinheritsched(&attr, PTHREAD_EXPLICIT_SCHED);
pthread_attr_setschedpolicy(&attr, SCHED_FIFO);
pthread_attr_setschedparam(&attr, &param);
pthread_attr_setstacksize(&attr, PTHREAD_STACK_MIN);

for(i=0;i<10000;i++){
 printf("Tour %d\n", i);
 if (err = pthread_create (&task,&attr,(void *)routine,NULL))
 fprintf(stderr, "failed to create threads: %s\n", strerror(err));
 if (err = pthread_create (&task,&attr,(void *)routine,NULL))
 fprintf(stderr, "failed to create threads: %s\n", strerror(err));
 if (err = pthread_create (&task,&attr,(void *)routine,NULL))
 fprintf(stderr, "failed to create threads: %s\n", strerror(err));

 nanosleep ( &timeout2, NULL);
}

nanosleep ( &timeout, NULL);
return 0;
}

At the turn 509, it doesn't work any more. Ressources are unavailable to
create another task.


Thanks

[-- Attachment #2: Type: text/html, Size: 2978 bytes --]

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [Xenomai-help] Problem API Posix : ressource temporarily unavailable
  2007-05-23 13:49 [Xenomai-help] Problem API Posix : ressource temporarily unavailable Perrine Martignoni
@ 2007-05-23 13:59 ` Gilles Chanteperdrix
  0 siblings, 0 replies; 2+ messages in thread
From: Gilles Chanteperdrix @ 2007-05-23 13:59 UTC (permalink / raw)
  To: Perrine Martignoni; +Cc: xenomai

Perrine Martignoni wrote:
> Hello,
>  
> I work on an ARM9 with the API Posix and I found a problem during my tests.
> I have written a simple example who show this problem.
> Here is my code :
>  
> #include <pthread.h>
> #include <string.h>
> #include <stdio.h>
> #include <signal.h>
> #include <time.h>
> #include <errno.h>
> #include <fcntl.h >
> #include <getopt.h>
> #include <unistd.h>
> #include <stdlib.h>
> #include <sys/mman.h>
> #include <sys/time.h>
> #include <limits.h>
> #include <mqueue.h>
> void routine (void * cookie);
> void routine (void * cookie)
> {
> struct timespec timeout;
> struct sched_param param = {.sched_priority = 10 };
> pthread_setschedparam(pthread_self(), SCHED_FIFO, &param);
> timeout.tv_sec=0;
> timeout.tv_nsec=200000000;
> 
> nanosleep ( &timeout, NULL);
> printf("destruction tache\n");
> pthread_exit(NULL);
> }
> 
> int main(int argc, char **argv)
> {
> int i = 0;
> int err;
> pthread_attr_t attr;
> pthread_t task;
> struct timespec timeout, timeout2;
> struct sched_param param = {.sched_priority = 10 };
> 
> mlockall(MCL_CURRENT | MCL_FUTURE);
> 
> timeout.tv_sec=50;
> timeout.tv_nsec=0;
> timeout2.tv_sec=0;
> timeout2.tv_nsec=500000000;
> 
> pthread_attr_init(&attr);
> pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_JOINABLE);
> pthread_attr_setinheritsched(&attr, PTHREAD_EXPLICIT_SCHED);
> pthread_attr_setschedpolicy(&attr, SCHED_FIFO);
> pthread_attr_setschedparam(&attr, &param);
> pthread_attr_setstacksize(&attr, PTHREAD_STACK_MIN);
> 
> for(i=0;i<10000;i++){
>  printf("Tour %d\n", i);
>  if (err = pthread_create (&task,&attr,(void *)routine,NULL))
>  fprintf(stderr, "failed to create threads: %s\n", strerror(err));
>  if (err = pthread_create (&task,&attr,(void *)routine,NULL)) 
>  fprintf(stderr, "failed to create threads: %s\n", strerror(err));
>  if (err = pthread_create (&task,&attr,(void *)routine,NULL))
>  fprintf(stderr, "failed to create threads: %s\n", strerror(err));
> 
>  nanosleep ( &timeout2, NULL);
> }
>  
> nanosleep ( &timeout, NULL);
> return 0;
> }
> 
>  
> At the turn 509, it doesn't work any more. Ressources are unavailable to
> create another task.

If you create a joinable thread, ressources remain allocated until the
thread is joined. If you do not intend to join your threads, then create
them detached.

-- 
                                                 Gilles Chanteperdrix


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2007-05-23 13:59 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2007-05-23 13:49 [Xenomai-help] Problem API Posix : ressource temporarily unavailable Perrine Martignoni
2007-05-23 13:59 ` Gilles Chanteperdrix

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.