How can I make a program do two things at the same time?

For example, the program would be generating prime numbers and storing them into dynamically allocated memory, but at the same time it would be printing on the console a kind of progress indicator like: | / -- \ | / -- (you get the idea, the rotating sticks thingy) independently from the generating prime numbers process.

Thanks!