Search code examples
namespacesvxworks

How to resolve naming conflicts when multiply instantiating a program in VxWorks


I need to run multiple instances of a C program in VxWorks (VxWorks has a global namespace). The problem is that the C program defines global variables (which are intended for use by a specific instance of that program) which conflict in the global namespace. I would like to make minimal changes to the program in order to make this work. All ideas welcomed!

Regards

By the way ... This isn't a good time to mention that global variables are not best practice!


Solution

  • The easiest thing to do would be to use task Variables (see taskVarLib documentation).

    When using task variables, the variable is specific to the task now in context. On a context switch, the current variable is stored and the variable for the new task is loaded.

    The caveat is that a task variable can only be a 32-bit number. Each global variable must also be added independently (via its own call to taskVarAdd?) and it also adds time to the context switch.

    Also, you would NOT be able to share the global variable with other tasks.
    You can't use task variables with ISRs.