[Click] multiple task in a element

Eddie Kohler kohler at icir.org
Mon Sep 22 12:32:14 EDT 2003


Shilpi,

> How can we run multiple task in a element. For a single task we can define
> run_task function, but if we want to have two tasks , how will we declare two
> methods ?

Use the other Task constructor:

    Task::Task(TaskHook, void *);

where TaskHook is the type "bool (*TaskHook)(Task *, void *)".

For instance,

  class Shilpi : public Element {
    ...
    Task _task1, _task2;
    static bool run_task2(Task *, void *); 
  };

  Shilpi::Shilpi()
    : _task1(this),     // will call Shilpi::run_task()
      _task2(run_task2, this)   // will call Shilpi::run_task2()
  { ... }

  bool Shilpi::run_task2(Task *, void *callback_data) {
    Shilpi *e = (Shilpi *)callback_data;
    ...
  }

> If we run router in multiple threads, define each task in separate thread, will
> it utilize CPU more effeciently ?

Check out Benjie and Robert's paper on this topic
http://www.pdos.lcs.mit.edu/papers/click:usenix01/

Eddie


More information about the click mailing list