[riot-users] Simple thread

Thomas Eichinger thomas.eichinger at fu-berlin.de
Tue Oct 21 14:39:07 CEST 2014


Hi Marcio,

welcome to RIOT! With the following modifications your code runs for me.
If there are open questions don’t hesitate to ask here.

Best, Thomas

```C
#include "board.h"
#include "pthread.h"
#include "hwtimer.h"

void *run(void *parameter) {
    for (int c = 0; c < 6; c++) {
        LED_GREEN_TOGGLE;
        hwtimer_wait(1000000);
    }
    return NULL;
}

int main(void)
{
    pthread_t th_id;
    pthread_attr_t th_attr;
    size_t arg = 6;
    pthread_attr_init(&th_attr);
    pthread_create(&th_id, &th_attr, run, (void *) arg);
    /* wait for run() */
    pthread_join(th_id, NULL);
    /* signal termination of run() */
    LED_RED_TOGGLE;
    return 0;
}
```
> On 21 Oct 2014, at 13:51, Marcio Segura <marciopps at gmx.com> wrote:
> 
> Hi friends,
>  
> I am tryng to do a very simple thread application, with will configure and blink a led, but it isn't working. Can you see if I made some mistake? This code on *run works ok if I put it on main(void). I am very newbie on Riot :-)
> Tahnks.
>  
> The code: 
>  
> void *run(void *parameter) {
>     gpio_init_out(21, GPIO_NOPULL);
>     gpio_init_out(22, GPIO_NOPULL);
>     gpio_init_out(23, GPIO_NOPULL);
>     for (int c = 0; c < 6; c++) {
>         LED_GREEN_TOGGLE;
>         hwtimer_wait(1000000);
>     }
>     return NULL;
> }
> int main(void)
> {
>     pthread_t th_id;
>     pthread_attr_t th_attr;
>     size_t arg = 6;
>     pthread_attr_init(&th_attr);
>     pthread_create(&th_id, &th_attr, run, (void *) arg);
>     while (1){}
>     return 0;
> }
> _______________________________________________
> users mailing list
> users at riot-os.org
> http://lists.riot-os.org/mailman/listinfo/users

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.riot-os.org/pipermail/users/attachments/20141021/2e4ee8e0/attachment.html>


More information about the users mailing list