Невозможно получить доступ к переменной при реализации многопоточности в contiki
Я пытаюсь реализовать многопоточность в contiki, но получаю Segmentation fault (core dumped)
при попытке распечатать переменную внутри функции обратного вызова потока. Я пытаюсь использовать следующий код:
static void program1(void *data)
{
int i;
for (i=0;i<10;i++)
{
printf("%d\n",i);
mt_yield();
}
}
static void program2(void *data)
{
int j;
for (j=0;j<10;j++)
{
printf("%d\n",j);
mt_yield();
}
}
PROCESS_THREAD(multi_threading_process, ev, data)
{
static struct mt_thread alpha_thread;
static struct mt_thread count_thread;
static struct etimer timer;
static int toggle;
PROCESS_BEGIN();
mt_init();
mt_start(&alpha_thread, program1, NULL);
mt_start(&count_thread, program2, NULL);
etimer_set(&timer, CLOCK_SECOND / 2);
while(1)
{
PROCESS_WAIT_EVENT();
if(ev == PROCESS_EVENT_TIMER)
{
if(toggle)
{
mt_exec(&alpha_thread);
toggle--;
}
else
{
mt_exec(&count_thread);
toggle++;
}
etimer_set(&timer, CLOCK_SECOND / 2);
}
}
mt_stop(&alpha_thread);
mt_stop(&count_thread);
mt_remove();
PROCESS_END();
}
Выход:
Contiki-list-1532-g2ca33d4 started with IPV6, RPL
Rime started with address 1.2.3.4.5.6.7.8
MAC nullmac RDC nullrdc NETWORK sicslowpan
Tentative link-local IPv6 address fe80:0000:0000:0000:0302:0304:0506:0708
Segmentation fault (core dumped)