Contiki中的多个进程在加载CPU时创建

时间:2017-06-21 08:00:22

标签: c contiki

我是contiki的新手。任何人都可以告诉我如何并行启动多个进程以创建CPU使用率拥塞。下面是我尝试的代码: -

#include "contiki.h"
#include <stdio.h>

PROCESS(cpu_load_process_1, "CPU Loading Process 1");
PROCESS(cpu_load_process_2, "CPU Loading Process 2");
PROCESS(cpu_load_process_3, "CPU Loading Process 3");
PROCESS(cpu_load_process_4, "CPU Loading Process 4");

AUTOSTART_PROCESSES(&cpu_load_process_1);
AUTOSTART_PROCESSES(&cpu_load_process_2);

PROCESS_THREAD(cpu_load_process_1, ev, data)
 {
   PROCESS_BEGIN();
   PROCESS_END();
 }
 PROCESS_THREAD(cpu_load_process_3, ev, data)
 {
  PROCESS_BEGIN();
  PROCESS_END();
 }

但是,这会产生如下错误: -

/home/user/contiki-3.0/core/./sys/autostart.h:48:24: error: redefinition of ‘autostart_processes’
struct process * const autostart_processes[] = {__VA_ARGS__, NULL}struct process * const autostart_processes[] = {__VA_ARGS__, NULL}

请指导我。任何创建CPU拥塞的替代方式/建议也会有所帮助。

1 个答案:

答案 0 :(得分:3)

在宏AUTOSTART_PROCESSES后面,隐藏了一个结构定义。

#define AUTOSTART_PROCESSES(...)                    \
    struct process * const autostart_processes[] = {__VA_ARGS__, NULL}

通过调用两次AUTOSTART_PROCESSES,您可以定义两次结构。

<强>解决方案:

鉴于宏参数,我想你应该写:

AUTOSTART_PROCESSES(&cpu_load_process_1, &cpu_load_process_2);

而不是

AUTOSTART_PROCESSES(&cpu_load_process_1);
AUTOSTART_PROCESSES(&cpu_load_process_2);