Hi,
I am starting out with rtLinux, and am having a funny problem in a simple
test program: it looks like after I call pthread_wait_np() for the first
time, the values of one of my variables change for no reason that I can see.
I can work around this if I have to, but I would rather not have unsolved
mysteries, so I would appreciate any advice. It seems likely that I just
don't understand some feature that I need to learn about.
The module is supposed to write data to an rtfifo and will eventually read
from a second one, which is why I try to pass an array of two fifo numbers as
arguments to start_routine. The pointer to the array appears to remain
unchanged, but the values pointed to do change, although only once. Output
from dmesg is after the code.
Here is the code. There are a lot of debugging rtl_printfs in it, so you can
see what happens with dmesg.
#include <rtl.h>
#include <time.h>
#include <pthread.h>
#include <rtl_fifo.h>
pthread_t thread;
void * start_routine(void *arg)
{
unsigned int *fifos = (unsigned int *) arg;
unsigned short values[4] = {0,1,2,3};
unsigned int counter = 0;
struct sched_param p;
p . sched_priority = 1;
pthread_setschedparam (pthread_self(), SCHED_FIFO, &p);
pthread_make_periodic_np (pthread_self(), gethrtime(), 500000000);//0.5
seconds
rtl_printf("pre-while fifo values are: %u write and %u
read\n",fifos[0],fifos[1]);
rtl_printf("pre-while fifo pointer is: %lu\n", (unsigned long) fifos);
while (1)
{
rtl_printf("fifo values before pthread_wait_np() are: %u write and %u
read\n",fifos[0],fifos[1]);
rtl_printf("fifo pointer before pthread_wait_np() is: %lu\n", (unsigned
long) fifos);
++counter;
pthread_wait_np ();
rtl_printf("fifo values after pthread_wait_np() are: %u write and %u
read\n",fifos[0],fifos[1]);
rtl_printf("fifo pointer after pthread_wait_np() is: %lu\n", (unsigned
long) fifos);
rtf_put(fifos[0],values,4*sizeof(unsigned short));
rtf_put(0,&counter,sizeof(counter));
}
return 0;
}
int init_module(void)
{
unsigned int fifos[2] = {0,1};//write to 0, read from 1
int i;
for (i = 0; i < 2; ++i)
{
rtf_destroy(fifos[i]);
rtl_printf("created rtfifo %d: %d\n", fifos[i],
rtf_create(fifos[i],2048));
}
return pthread_create (&thread, NULL, start_routine, (void *)fifos);
}
void cleanup_module(void)
{
unsigned int fifos[2] = {0,1};//write to 0, read from 1
int i;
for (i = 0; i < 2; ++i)
{
rtl_printf("destroyed rtfifo %d: %d\n", fifos[i],
rtf_destroy(fifos[i]));
}
pthread_delete_np (thread);
}
---------------Output from dmesg -------------------------
RTLinux Extensions Loaded (http://www.fsmlabs.com/)
created rtfifo 0: 0
created rtfifo 1: 0
pre-while fifo values are: 0 write and 1 read
pre-while fifo pointer is: 3372441380
fifo values before pthread_wait_np() are: 0 write and 1 read
fifo pointer before pthread_wait_np() is: 3372441380
fifo values after pthread_wait_np() are: 3550217344 write and 128 read
fifo pointer after pthread_wait_np() is: 3372441380
fifo values before pthread_wait_np() are: 3550217344 write and 128 read
fifo pointer before pthread_wait_np() is: 3372441380
fifo values after pthread_wait_np() are: 3550217344 write and 128 read
fifo pointer after pthread_wait_np() is: 3372441380
fifo values before pthread_wait_np() are: 3550217344 write and 128 read
fifo pointer before pthread_wait_np() is: 3372441380
destroyed rtfifo 0: 0
destroyed rtfifo 1: 0
Thanks,
Pablo Alvarez ([EMAIL PROTECTED])
-- [rtl] ---
To unsubscribe:
echo "unsubscribe rtl" | mail [EMAIL PROTECTED] OR
echo "unsubscribe rtl <Your_email>" | mail [EMAIL PROTECTED]
--
For more information on Real-Time Linux see:
http://www.rtlinux.org/