Hi nickmagus,
I'd recommend you use the WPILib Task class, which is a simple wrapper over the VxWorks task/thread API. Here's some sample code to get you started:
To define a task, you have to give it a name. The task will show up in debugging as FRC_task_name, where task_name is the value passed to the Task constructor. The second argument to the constructor is a FUNCPTR, which is your threading function.
Code:
MyRobot::RobotInit()
{
Task myTask("image_process", imageProcessThread);
myTask.Start();
}
The thread function
must return an int and take a variable number of arguments (up to 10), which is denoted in C/C++ by "..." as the last function argument.
Your task will run from start to finish once, after Start is called. If you don't want it to be deleted, then put a loop in it so it doesn't return until you're done:
Code:
int imageProcessThread(...)
{
va_arg argptr;
// do stuff...
}
To get access to any of your 10 arguments, you must use the va_arg macros, which are explained here:
http://www.cppreference.com/wiki/c/other/va_arg
If you are using shared data between threads, you must be sure to enforce synchronization between the threads. WPILib has an interesting abstraction for synchronization with semaphores - examples are in the C++ Programming Guide - but it's really more confusing in my opinion. PM me if you need help with synchronization.