views:

41

answers:

2

I have several threads which act as backup for the main one spending most of their life blocked by sem_wait(). Is it OK to keep them or is it better to spawn new threads only when they need to do actual work? Does kernel switch to threads waiting on sem_wait() and "waste" CPU cycles?

Thanks.

A: 

Choose option A.

The wasted cycles are minor. Your threads will always be in wait state.

On the other hand, the complexity of starting and stopping threads, instead of having them all up may seriously harm your program logic.

Pavel Radzivilovsky
+3  A: 

No, blocked threads are never switched in for any common thread library and operating system (it would be an extremely badly designed one where they were). But they will still use memory, of course.

Autopulated