From: Gilles Chanteperdrix <gilles.chanteperdrix@xenomai.org>
To: Laurent.POYART@fr.thalesgroup.com
Cc: xenomai@xenomai.org
Subject: Re: [Xenomai-help] Problem using xenomai threads with eclipse
Date: Thu, 19 Jun 2008 02:16:12 +0200 [thread overview]
Message-ID: <4859A54C.1070302@domain.hid> (raw)
In-Reply-To: <2F8EE677D406514ABE53EF9C0934A666042ABE7E@anubis2.clb.tcfr.thales>
Laurent.POYART@fr.thalesgroup.com wrote:
> Hi,
>
> I'm compiling a xenomai user land application using eclipse CDT 3.2.2 and
> my Pc hangs when I run it using debug (gbd).
>
> Context:
>
> Linux kernel : 2.6.23
> Xenomai : 2.4.1
> Architecture: Pentium Dual Core (PC).
> Xenomai Configuration : priority coupling.
> Linker options: -Wl,--wrap,pthread_create -Wl,-soname=pthread_rt
> (only pthread_create is wrapped)
>
> The application code is the following (the problem is described after the
> source code):
>
> #include<iostream>
> #include<cassert>
> using namespace std;
>
> #include <sys/mman.h>
> #include <pthread.h>
> #include <semaphore.h>
> #include <mqueue.h>
> #include <errno.h>
>
> // Lock used to make the thread wait for start enable
> sem_t s_SemThreadStartEnable;
>
> // For Test
> sem_t s_SemThreadTest;
>
> // Thread function for the Xenomai RT Thread
> void* mythreadfunctionrt(void* arg)
> {
> // Wait start Enable (not wrapped => linux syscall)
> int result = sem_wait(&s_SemThreadStartEnable);
> assert(result == 0);
>
> // Enter Thread Loop
> while(1)
> {
> // Wait for lock test (is not available => must preempt the
> thread)
> result = sem_wait(&s_SemThreadTest);
> assert(result == 0);
>
> // Never reach this point because lock is never released
> }
>
> return(0);
> }
>
> // Thread function for the linux Thread (not RT)
> void* mythreadfunction(void* arg)
> {
> mq_attr mqAttributs;
> mqAttributs.mq_flags = 0;
> mqAttributs.mq_maxmsg = 1;
> mqAttributs.mq_msgsize = sizeof(void*);
> mqAttributs.mq_curmsgs = 0;
> // generates name
> mqd_t handle = mq_open("/OEmqTest",(O_RDWR | O_CREAT),(S_IRWXU |
> S_IRWXG),&mqAttributs);
> assert(handle >= 0);
>
> while(1)
> {
> // Pend on the message queue (message is a pointer size =
> sizeof(void*))
> char* pt_obj = 0;
> cout << "block on mqueue reception" << endl;
> int result =
> mq_receive(handle,(char*)&pt_obj,sizeof(void*),0);
> assert(result == 0);
> }
>
> return(0);
> }
>
> // ================================================================
> // Function : AppStartTask
> // Goal : Application Start Task
> // ================================================================
> void* AppStartTask(void *p_arg)
> {
> // ================ LINUX THREAD (NOT RT) ====================
> // ================ REAL TIME PRIORITY => 12 / SCHED FIFO ==========
> cout << "Create Linux Thread" << endl;
> // Thread Attributs Init
> pthread_t mythread;
> pthread_attr_t threadAttributs;
> int result = pthread_attr_init(&threadAttributs);
> assert(result == 0);
> struct sched_param scheduleParams;
> scheduleParams.sched_priority = 12;
> result =
> pthread_attr_setschedparam(&threadAttributs,&scheduleParams);
> assert(result == 0);
> pthread_attr_setschedpolicy (&threadAttributs,SCHED_FIFO);
> assert(result == 0);
> pthread_attr_setinheritsched
> (&threadAttributs,PTHREAD_EXPLICIT_SCHED);
> assert(result == 0);
> result = __real_pthread_create(&mythread,
> &threadAttributs,
> mythreadfunction,
> 0);
> assert(result == 0);
>
> // Lock that enable RT thread loop
> sem_init(&s_SemThreadStartEnable,false,0); // not available
>
> // Test Lock
> sem_init(&s_SemThreadTest,false,0); // not
> available
>
> // ================ XENOMAI THREAD ====================
> // ======= REAL TIME PRIORITY => 11 / SCHED FIFO =======
> cout << "Create Xenomai Thread" << endl;
> pthread_t mythreadrt;//
> pthread_attr_t threadAttributsrt;
> int resultrt = pthread_attr_init(&threadAttributsrt);
> assert(resultrt == 0);
> struct sched_param scheduleParamsrt;
> scheduleParamsrt.sched_priority = 11;
> resultrt =
> pthread_attr_setschedparam(&threadAttributsrt,&scheduleParamsrt);
> assert(resultrt == 0);
> result = pthread_attr_setschedpolicy
> (&threadAttributsrt,SCHED_FIFO);
> assert(resultrt == 0);
> resultrt = pthread_attr_setinheritsched
> (&threadAttributsrt,PTHREAD_EXPLICIT_SCHED);
> assert(resultrt == 0);
> resultrt = pthread_create(&mythreadrt,
> &threadAttributsrt,
> mythreadfunctionrt,
> 0);
> ////// NOTE : NO PROBLEM IF A REPLACE pthread_create by
> __real_pthread_create
>
> assert(resultrt == 0);
>
>
> // Enable Thread Start
> cout << "Enable Thread Loop Start" << endl;
> resultrt = sem_post(&s_SemThreadStartEnable);
> assert(result == 0);
>
> // Suspend AppTask
> sem_t lockEnd;
> sem_init(&lockEnd,false,0); // not available
> cout << "Infinite wait end app" << endl;
> sem_wait(&lockEnd);
>
> return(0);
> }
>
> // Function : Main
> int main(int argc,char* argv[])
> {
> // Mlock All for Xenomai
> mlockall(MCL_CURRENT | MCL_FUTURE);
>
> AppStartTask(0);
>
> return 0;
> }
>
> Problem description:
> when I run the application with eclipse using "run" command (no debug using
> gdb) the application run correctly and I can stop it from eclipse.
> The console output is:
> Create Linux Thread
> block on mqueue reception
> Create Xenomai Thread
> Enable Thread Loop Start
> Infinite wait end app
>
> when I launch the application with eclipse using "debug" command (gdb is
> run). The console output is the same but when I stop the application, the PC
> hangs (I need to push the reset button).
>
> this problem doesn't occur when I only use linux standard threads (all
> __real_pthread_create).
>
> Do you have any idea? I'm I doing something totally wrong in my example.
When running under gdb, a lot of signals are sent, so, you should be
prepared to restart syscalls when EINTR is returned, instead of simply
failing with assert. However, assert should not cause your system to freeze.
Can you get any kernel messages, either by redirecting the console to a
serial driver, or by running your example (with gdb) in plain text mode ?
--
Gilles.
next prev parent reply other threads:[~2008-06-19 0:16 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2008-06-18 13:04 [Xenomai-help] Problem using xenomai threads with eclipse Laurent.POYART
2008-06-19 0:16 ` Gilles Chanteperdrix [this message]
2008-06-20 10:56 ` Jan Kiszka
2008-06-20 12:15 ` Gilles Chanteperdrix
-- strict thread matches above, loose matches on Subject: below --
2008-06-19 13:29 Laurent.POYART
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=4859A54C.1070302@domain.hid \
--to=gilles.chanteperdrix@xenomai.org \
--cc=Laurent.POYART@fr.thalesgroup.com \
--cc=xenomai@xenomai.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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.