Re: [riot-devel] Condition Variables

2016-08-18 Thread Simon Brummer
Hi Sam,

The hole message passing avoidance is actually a pretty good point. I
prefer message passing because I can handle the hole User Function call
Timeout Handling with it as well. It would be interesting if a condition
change could occur based on the expiration of a Timer.

Just my thoughts on that.

Cheers Simon

Am 18.08.2016 6:42 nachm. schrieb "Sam Kumar" :

Thanks for the advice, Simon, Martin, and Kaspar!

For now, I'll use a mutex together with thread_flags. Using message
passing, as Simon suggested, would work for me as well; the reason I find
thread_flags preferable is that I need to block application threads that
call send() and receive(), that may already be using message passing.

If people don't mind, and they think it would be useful, I'm also willing
to contribute a lightweight condition variable to the core module. I think
it could be implemented simply as a queue, just like the current mutex
implementation.

Sam

On Wed, Aug 17, 2016 at 10:19 AM, Kaspar Schleiser 
wrote:

> Hey,
>
> On 08/16/2016 09:49 PM, Sam Kumar wrote:
> > If not, I want to learn if there is another structured way to
> > block a thread until an event, that I should use instead.
>
> maybe thread_flags work for your use-case.
>
> Kaspar
> ___
> devel mailing list
> devel@riot-os.org
> https://lists.riot-os.org/mailman/listinfo/devel
>


___
devel mailing list
devel@riot-os.org
https://lists.riot-os.org/mailman/listinfo/devel
___
devel mailing list
devel@riot-os.org
https://lists.riot-os.org/mailman/listinfo/devel


Re: [riot-devel] Condition Variables

2016-08-18 Thread Sam Kumar
Thanks for the advice, Simon, Martin, and Kaspar!

For now, I'll use a mutex together with thread_flags. Using message
passing, as Simon suggested, would work for me as well; the reason I find
thread_flags preferable is that I need to block application threads that
call send() and receive(), that may already be using message passing.

If people don't mind, and they think it would be useful, I'm also willing
to contribute a lightweight condition variable to the core module. I think
it could be implemented simply as a queue, just like the current mutex
implementation.

Sam

On Wed, Aug 17, 2016 at 10:19 AM, Kaspar Schleiser 
wrote:

> Hey,
>
> On 08/16/2016 09:49 PM, Sam Kumar wrote:
> > If not, I want to learn if there is another structured way to
> > block a thread until an event, that I should use instead.
>
> maybe thread_flags work for your use-case.
>
> Kaspar
> ___
> devel mailing list
> devel@riot-os.org
> https://lists.riot-os.org/mailman/listinfo/devel
>
___
devel mailing list
devel@riot-os.org
https://lists.riot-os.org/mailman/listinfo/devel


Re: [riot-devel] Condition Variables

2016-08-17 Thread Kaspar Schleiser
Hey,

On 08/16/2016 09:49 PM, Sam Kumar wrote:
> If not, I want to learn if there is another structured way to
> block a thread until an event, that I should use instead.

maybe thread_flags work for your use-case.

Kaspar
___
devel mailing list
devel@riot-os.org
https://lists.riot-os.org/mailman/listinfo/devel


Re: [riot-devel] Condition Variables

2016-08-17 Thread Martin

Hi Sam,


in its core RIOT only provides a small and efficient mutex implementation.

Condition variables are provided within the POSIX wrapper [1], 
specifically in the the pthread part [2].


To get an idea how use the provided condition variables you can have a 
look in our tests for it [3].


But as Simon stated you should consider if using the Message passing 
possibilities of RIOT could have the desired effect,


since using the POSIX condition variables in RIOT also comes with a 
certain overhead.



Best regards,

Martin

[1] http://riot-os.org/api/group__posix.html
[2] http://riot-os.org/api/group__pthread.html
[3] 
https://github.com/RIOT-OS/RIOT/tree/master/tests/pthread_condition_variable


Am 08/17/2016 um 11:21 AM schrieb Simon Brummer:

Dear fellow TCP implementor,

The common way implement something like this in RIOT is Message
passing. Your thread simply blocks by calling msg_receive() until it
received a message from another thread. As soon as you receive a
Packet, send a message to the via msg_send() function to wake the
blocked thread.

Cheers
Simon Brummer

Am Dienstag, den 16.08.2016, 12:49 -0700 schrieb Sam Kumar:

Hello,
I was looking at the synchronization primitives in RIOT OS. I noticed
that there is a mutex implementation, but I was unable to find a
condition variable.

I am currently porting the TCP logic from the FreeBSD operating
system to RIOT as part of the research work I am doing. I am
implementing the "conn" API for TCP, and I need to be able to block
the current thread until a packet is received, to implement some of
the functions.

I read the IPC implementation (msg.c), which also has a blocking API,
and saw that it interacts with the scheduler manually in order to
block and resume threads. Before I did the same thing for the conn
API (or perhaps implement/contribute my own condition variable), I
wanted to ask whether there are condition variables for RIOT, in case
I was just looking in the wrong place. If not, I want to learn if
there is another structured way to block a thread until an event,
that I should use instead.

Thanks,
Sam Kumar
___
devel mailing list
devel@riot-os.org
https://lists.riot-os.org/mailman/listinfo/devel

___
devel mailing list
devel@riot-os.org
https://lists.riot-os.org/mailman/listinfo/devel


___
devel mailing list
devel@riot-os.org
https://lists.riot-os.org/mailman/listinfo/devel


Re: [riot-devel] Condition Variables

2016-08-17 Thread Simon Brummer
Dear fellow TCP implementor,

The common way implement something like this in RIOT is Message
passing. Your thread simply blocks by calling msg_receive() until it
received a message from another thread. As soon as you receive a
Packet, send a message to the via msg_send() function to wake the
blocked thread. 

Cheers 
   Simon Brummer

Am Dienstag, den 16.08.2016, 12:49 -0700 schrieb Sam Kumar:
> Hello,
> I was looking at the synchronization primitives in RIOT OS. I noticed
> that there is a mutex implementation, but I was unable to find a
> condition variable.
> 
> I am currently porting the TCP logic from the FreeBSD operating
> system to RIOT as part of the research work I am doing. I am
> implementing the "conn" API for TCP, and I need to be able to block
> the current thread until a packet is received, to implement some of
> the functions.
> 
> I read the IPC implementation (msg.c), which also has a blocking API,
> and saw that it interacts with the scheduler manually in order to
> block and resume threads. Before I did the same thing for the conn
> API (or perhaps implement/contribute my own condition variable), I
> wanted to ask whether there are condition variables for RIOT, in case
> I was just looking in the wrong place. If not, I want to learn if
> there is another structured way to block a thread until an event,
> that I should use instead.
> 
> Thanks,
> Sam Kumar
> ___
> devel mailing list
> devel@riot-os.org
> https://lists.riot-os.org/mailman/listinfo/devel
___
devel mailing list
devel@riot-os.org
https://lists.riot-os.org/mailman/listinfo/devel


[riot-devel] Condition Variables

2016-08-16 Thread Sam Kumar
Hello,
I was looking at the synchronization primitives in RIOT OS. I noticed that
there is a mutex implementation, but I was unable to find a condition
variable.

I am currently porting the TCP logic from the FreeBSD operating system to
RIOT as part of the research work I am doing. I am implementing the "conn"
API for TCP, and I need to be able to block the current thread until a
packet is received, to implement some of the functions.

I read the IPC implementation (msg.c), which also has a blocking API, and
saw that it interacts with the scheduler manually in order to block and
resume threads. Before I did the same thing for the conn API (or perhaps
implement/contribute my own condition variable), I wanted to ask whether
there are condition variables for RIOT, in case I was just looking in the
wrong place. If not, I want to learn if there is another structured way to
block a thread until an event, that I should use instead.

Thanks,
Sam Kumar
___
devel mailing list
devel@riot-os.org
https://lists.riot-os.org/mailman/listinfo/devel