This is the mail archive of the mailing list for the eCos project.

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

POSIX problems during ARM simulations

I have been having some troubles with getting twothreads.c running when
POSIX has been added to the list of available packages.  I am running on
CYGWIN and have tried it under both SID and the Insight simulator with the
same results.  When I run, all the output I see is:

   Entering twothreads' main() function
   Beginning execution; thread data is 1
   Beginning execution; thread data is 2

If I remove the POSIX package from the application and rebuild eCos and
twothreads, I can successfully run the example and get the expected output.
Does anyone know what I may be doing wrong?   It seems everytime I break, I
am sitting in idle_thread_main().

Other version numbers that may be helpful are listed below in case there is
a known toolchain problem that I need to work around or upgrade/downgrade

	eCos v2.0
	platform -> simulating arm7PID

I have also modified twothreads.c to use straight POSIX calls and start any
support threads from main and this has not helped.   A stripped down copy of
this is included below if anyone wants to test it out or in the future, use
it as the base for learning how to (or how not to) do POSIX on eCos.  I have
also reduced the nanosecond values down to just a single nanosecond in case
there is a significant simulation delay and this had no effect.  You can
also go to to get a copy of this file as well
as the eCos 'ecc' file that I am trying to use.

	- Chip

=========== begin ptwothreads.c ===============
#include <cyg/kernel/kapi.h>

#include <stdio.h>
#include <math.h>
#include <stdlib.h>
#include <pthread.h>
#include <time.h>      // For delay capabilities

static void simple_program(void* data);

pthread_mutex_t cliblock;   /* For C library (printf) protection */

int main(int argc, char* argv[])
  printf("Entering ptwothreads' main() function\n");

  if (pthread_mutex_init(&cliblock, NULL) == 0)
    pthread_attr_t attr;
    pthread_t      thread_id;

    // Set up our thread attributes

    if (   (pthread_attr_init(&attr) == 0)
        && (pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED) ==
      // Start our first thread

      if (pthread_create(&thread_id, &attr,
                         (void*(*)(void*))simple_program, (void*)1) == 0)
        pthread_create(&thread_id, &attr,
                       (void*(*)(void*))simple_program, (void*)2);
  return 0;
// this is a simple program which runs in a thread

static void simple_program(void* data)
  int  message = (int)data;
  long delay   = 200;

      printf("Beginning execution; thread data is %d\n", message);

  for (;;)
    // Delay 'delay' milliseconds

    struct timespec rqtp = { 0 };
    rqtp.tv_nsec = delay * 1000 * 1000; // Convert from mS to nS
    nanosleep(&rqtp, NULL);

        printf("Thread %d: and now a delay of %d clock ticks\n",
               message, delay);

    // Calculate next delay amount

    delay = 200 + (rand() % 50);
=========== end ptwothreads.c ===============

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]