Skip to contentSkip to conversation

Interprocess Mutex

Xenomai-help Adrian Boeing 3 participants 4 messages Nov 20, 2008 – Nov 21, 2008

lore
Share & tools
lore
#0 lore raw

Hi,

Is it possible to create an inter-process mutex between kernel space and user space?
If so, how is this done with the native API?

The system has one real-time kernel process which communicates with other processes via shared memory.

Thanks,
-Adrian

#1 lore raw
Quoted 8 lines · Adrian Boeing

Hi,

Is it possible to create an inter-process mutex between kernel space and user space?
If so, how is this done with the native API?

The system has one real-time kernel process which communicates with other processes via shared memory.

See rt_mutex_bind:
http://www.xenomai.org/documentation/branches/v2.4.x/html/api/group__mutex.html#g39b3a0e7f6f6ee41b8068ed59e25d1d1
or, for the posix skin, pthread_mutexattr_setpshared:
http://www.xenomai.org/documentation/branches/v2.4.x/html/api/group__posix__mutex.html#g73bd8697b91e0ee9a63c30052ac9f72f
Note that for sharing a mutex with the posix skin, the pthread_mutex_t structure needs to reside on a shared memory.

Signature · 1 line
                    Gilles.
#2 lore raw

Hi Gilles, thanks for the reply.

In my test (pseudo) code with rt_mutex:
(without bind):
int main() {
err = rt_mutex_create(&mutex_desc,0);
err = rt_mutex_acquire(&mutex_desc,TM_INFINITE); //fails with -1!
}
(with bind):
int main() {
err = rt_mutex_create(&Kmutex_desc,"bob");
err = rt_mutex_bind(&mutex_desc,"bob",TM_INFINITE);
err = rt_mutex_acquire(&mutex_desc,TM_INFINITE); //fails with -1!
}

Both of these fail to acquire the mutex with "EPERM" :: (this service was called from a context which cannot be given the ownership of the mutex).

Is there something special I need to do in order to do this in user space?

Thanks,
-Adrian

Quoted 24 lines · Gilles Chanteperdrix
Quoted 8 lines · Adrian Boeing

Hi,

Is it possible to create an inter-process mutex between kernel space and user space?
If so, how is this done with the native API?

The system has one real-time kernel process which communicates with other processes via shared memory.

See rt_mutex_bind:

http://www.xenomai.org/documentation/branches/v2.4.x/html/api/group__mutex.html#g39b3a0e7f6f6ee41b8068ed59e25d1d1
or, for the posix skin, pthread_mutexattr_setpshared:

http://www.xenomai.org/documentation/branches/v2.4.x/html/api/group__posix__mutex.html#g73bd8697b91e0ee9a63c30052ac9f72f
Note that for sharing a mutex with the posix skin, the pthread_mutex_t structure needs to reside on a shared memory.

--
Gilles.

#3 lore raw
Quoted 5 lines · Adrian Boeing

Hi Gilles, thanks for the reply.

In my test (pseudo) code with rt_mutex:
(without bind):
int main() {

   err = rt_task_shadow(...);
Quoted 5 lines

err = rt_mutex_create(&mutex_desc,0);
err = rt_mutex_acquire(&mutex_desc,TM_INFINITE); //fails with -1!
}
(with bind):
int main() {

   err = rt_task_shadow(...);
Quoted 10 lines

err = rt_mutex_create(&Kmutex_desc,"bob");
err = rt_mutex_bind(&mutex_desc,"bob",TM_INFINITE);
err = rt_mutex_acquire(&mutex_desc,TM_INFINITE); //fails with -1!
}

Both of these fail to acquire the mutex with "EPERM" :: (this service was called from a context which cannot be given the ownership of the mutex).

Is there something special I need to do in order to do this in user space?

Those Xenomai syscalls are only available to Xenomai threads; rt_task_shadow() turns a regular Linux pthread into a Xenomai-enabled RT thread. rt_task_shadow() has to be called once when you don't want to spawn a new RT task using the rt_task_create() interface, but promote the current Linux pthread to the Xenomai real-time domain. In short, it associates a Xenomai task control block to the underlying Linux task, so that both Xenomai and Linux schedulers can handle it.

Quoted 38 lines

Thanks,
-Adrian

On Thu, Nov 20, 2008 at 9:48 PM, Gilles Chanteperdrix <[email protected] <mailto:[email protected]>> wrote:

Adrian Boeing wrote:
> Hi,
>
> Is it possible to create an inter-process mutex between kernel space and
> user space?
> If so, how is this done with the native API?
>
> The system has one real-time kernel process which communicates with other
> processes via shared memory.

See rt_mutex_bind:
http://www.xenomai.org/documentation/branches/v2.4.x/html/api/group__mutex.html#g39b3a0e7f6f6ee41b8068ed59e25d1d1
or, for the posix skin, pthread_mutexattr_setpshared:
http://www.xenomai.org/documentation/branches/v2.4.x/html/api/group__posix__mutex.html#g73bd8697b91e0ee9a63c30052ac9f72f
Note that for sharing a mutex with the posix skin, the pthread_mutex_t structure needs to reside on a shared memory.

--
Gilles.

------------------------------------------------------------------------

_______________________________________________
Xenomai-help mailing list
[email protected]
https://mail.gna.org/listinfo/xenomai-help

Signature · 1 line
Philippe.