POSIX threads won't execute concurrently?
Martin Galvan
martin.galvan at tallertechnologies.com
Wed Aug 27 18:11:42 UTC 2014
On Wed, Aug 27, 2014 at 3:00 PM, Joel Sherrill
<joel.sherrill at oarcorp.com> wrote:
> It all depends on how you created them, scheduler attributes, priority,
> RTEMS
> configuration, etc.
>
> Can you post the code?
>
> --joel
Sure, here you go:
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include <sched.h>
#include <pthread.h>
#include <rtems.h>
#include <stdio.h>
#include <stdlib.h>
#include <limits.h>
#include <bsp.h> /* for device driver prototypes */
void* thread(void* arg)
{
int i;
for (i = 0; i < INT_MAX; i++) {
printf("Thread %d\n", pthread_self());
}
printf("End of thread %d\n", pthread_self());
return 0;
}
void* POSIX_Init()
{
pthread_t id1, id2;
if (pthread_create(&id1, NULL, thread, NULL) != 0) {
perror("Thread 1");
}
if (pthread_create(&id2, NULL, thread, NULL) != 0) {
perror("Thread 2");
}
if (pthread_join(id1, NULL) != 0) {
perror("Join 1");
}
if (pthread_join(id2, NULL) != 0) {
perror("Join 2");
}
puts("Done.");
exit(0);
}
#define CONFIGURE_APPLICATION_NEEDS_CLOCK_DRIVER
#define CONFIGURE_APPLICATION_NEEDS_CONSOLE_DRIVER
#define CONFIGURE_MICROSECONDS_PER_TICK 1000 /* 1 millisecond */
#define CONFIGURE_TICKS_PER_TIMESLICE 20 /* 20 milliseconds */
#define CONFIGURE_MAXIMUM_POSIX_THREADS 4
#define CONFIGURE_USE_DEVFS_AS_BASE_FILESYSTEM
#define CONFIGURE_POSIX_INIT_THREAD_TABLE
#define CONFIGURE_INIT
#include <rtems/confdefs.h>
One more thing: for some reason, if I use
CONFIGURE_MAXIMUM_POSIX_THREADS with a number greater than 4, I don't
see any output when running my program.
> On 8/27/2014 12:58 PM, Martin Galvan wrote:
>> Hi everyone! I'm trying to run a simple program to test how RTEMS
>> handles concurrency when using POSIX threads. My code is fairly
>> simple: it creates two pthreads with each one printing its name in a
>> loop. Normally I'd get something like:
>>
>> Thread 1
>> Thread 1
>> Thread 2
>> Thread 2
>> Thread 1
>> Thread 1
>> Thread 2
>> ...
>>
>> and so on. However, when I try this on RTEMS the second thread will
>> begin execution only after the first one ends, thus resulting in
>> something like:
>>
>> Thread 1
>> Thread 1
>> Thread 1
>> ...
>> End of Thread 1.
>> Thread 2
>> Thread 2
>> Thread 2
>> ...
>> End of Thread 2.
>>
>> I'm using the following configuration:
>>
>> #define CONFIGURE_APPLICATION_NEEDS_CLOCK_DRIVER
>> #define CONFIGURE_APPLICATION_NEEDS_CONSOLE_DRIVER
>> #define CONFIGURE_MICROSECONDS_PER_TICK 1000 /* 1 millisecond */
>> #define CONFIGURE_TICKS_PER_TIMESLICE 20 /* 20 milliseconds */
>> #define CONFIGURE_MAXIMUM_POSIX_THREADS 4
>> #define CONFIGURE_USE_DEVFS_AS_BASE_FILESYSTEM
>> #define CONFIGURE_POSIX_INIT_THREAD_TABLE
>> #define CONFIGURE_INIT
>>
>> #include <rtems/confdefs.h>
>>
>> Am I doing something wrong here?
>> _______________________________________________
>> users mailing list
>> users at rtems.org
>> http://lists.rtems.org/mailman/listinfo/users
>
> --
> Joel Sherrill, Ph.D. Director of Research & Development
> joel.sherrill at OARcorp.com On-Line Applications Research
> Ask me about RTEMS: a free RTOS Huntsville AL 35805
> Support Available (256) 722-9985
>
More information about the users
mailing list