All of lore.kernel.org
 help / color / mirror / Atom feed
* [Xenomai-help] POSIX skin, simple example with mutex not working...
@ 2009-07-23 15:17 Kolja Waschk
  2009-07-23 15:30 ` Gilles Chanteperdrix
  0 siblings, 1 reply; 7+ messages in thread
From: Kolja Waschk @ 2009-07-23 15:17 UTC (permalink / raw)
  To: xenomai

[-- Attachment #1: Type: TEXT/PLAIN, Size: 1155 bytes --]

Hi,

As a newcomer to Xenomai, I was until now successfully experimenting
with the native skin. Now that it comes to run an existing application
that is written for POSIX threads, a few problems show up. The
pthread_mutex_lock() _always_ returns 1 (EPERM) to me, although there
are no forks involved and policy should have been to SCHED_FIFO.

If that's of interest, I'm developing for a Blackfin uClinux (NOMMU)
target with newest uClinux-dist snapshot (Kernel
2.6.30.2-ADI-2010R1-pre, Xenomai 2.4.91, Nucleus v2.5-rc2) with FDPIC
userland. For building,  I simply used

> bfin-linux-uclibc-gcc `/usr/xenomai/bin/xeno-config --posix-cflags`
>   `/usr/xenomai/bin/xeno-config --posix-ldflags`  try.c -o try

Writing an explicit command line including the -Wl,@(wrapper) etc.
doesn't change anything.  The output of the attached code, compiled,
shows the return value from mutex_lock, first called from the NRT
main(), then from a thread that IMHO should run as a realtime thread:

> main:lock:1
> main:unlock:1
> thread:lock:1
> thread:unlock:1

Possibly I just missed some include file, compiler flag, .... or basic concept?

Thanks for any advice
Kolja

[-- Attachment #2: Type: TEXT/x-csrc, Size: 1379 bytes --]

#include <stdio.h>
#include <sys/mman.h>
#include <pthread.h>
#include <posix/posix.h>

static pthread_t task;

int try_mutex(const char *where);

void *body (void *unused)
{
    try_mutex("thread");

    pthread_exit(0);
}

int main (int argc, char *argv[])
{
    int r;
    pthread_attr_t attr;
    struct sched_param parm;

    mlockall(MCL_CURRENT|MCL_FUTURE);

    try_mutex("main");

    parm.sched_priority = 1;
    pthread_attr_init(&attr);
    pthread_attr_setinheritsched(&attr, 1);
    pthread_attr_setstacksize(&attr, 16384);
    pthread_attr_setschedparam(&attr, &parm);
    pthread_attr_setschedpolicy(&attr, SCHED_FIFO);

    r = pthread_create(&task, &attr, &body, NULL);
    if (r) printf("main:create:%d\n", r);

    r = pthread_join(task, 0);
    if (r) printf("main:join:%d\n", r);

    pthread_attr_destroy(&attr);

    return 0;
}

int try_mutex(const char *where)
{
    int r;
    pthread_mutex_t mx;
    pthread_mutexattr_t attr;
    pthread_mutexattr_init(&attr);

    r = pthread_mutex_init(&mx, &attr);
    if (r) printf("%s:init:%d\n", where, r);

    r = pthread_mutex_lock(&mx);
    if (r) printf("%s:lock:%d\n", where, r);

    r = pthread_mutex_unlock(&mx);
    if (r) printf("%s:unlock:%d\n", where, r);

    pthread_mutexattr_destroy(&attr);
    pthread_mutex_destroy(&mx);
}




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

end of thread, other threads:[~2009-07-24 15:25 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2009-07-23 15:17 [Xenomai-help] POSIX skin, simple example with mutex not working Kolja Waschk
2009-07-23 15:30 ` Gilles Chanteperdrix
     [not found]   ` <Pine.LNX.4.62.0907231741280.9450@domain.hid>
2009-07-23 17:55     ` Gilles Chanteperdrix
2009-07-23 19:28       ` Kolja Waschk
2009-07-23 20:27         ` Philippe Gerum
2009-07-23 21:23           ` Philippe Gerum
2009-07-24 15:25             ` Kolja Waschk

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.