Multithreading

I am writing some code that will receive serial data from a Windows program which will comprise a single character and a value that represents a length of time. This serial data will be sent whenever an event is fired, say a button push our mouse click. More or less the Arduino is taking that serial data and turning on a relay for a given amount of time. I am using a steady 5 V signal to actuate the relay, and it is non latching. The problem arises when I try to send multiple messages and a new message is received before the previous signal has been turned off. Is there a way to multithread or at least mimic it to the extent that I don't have to wait for the delay time from the previous message before activating a new relay?

Nathan

the extent that I don't have to wait for the delay time

Have a look at the blink without delay tutorial.

See following topic:
http://arduino.cc/forum/index.php/topic,66062.0.html

Blink without delay for sure.
Think of it as checking the time (usings millis() or micros()) when the action started and setting a flag and staring your action (relay on)
Next pass thru loop, check if the action is ongoing (flag is set?) and if enough time has passed to stop the action (if (millis() >= (start_time + duration)), if so stop the action (relay off) and clear the flag.
Can have as many of those going as you want.