3

如何并行启动多个进程以造成 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 拥塞的替代方式/建议也会有所帮助。

4

1 回答 1

4

在宏后面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);
于 2017-06-21T12:29:41.790 回答