multithreading - Thread pool configurations problems -


note i'm not talking specific implementation in specific language.

lets have thread pool , task queue. when thread runs pops task task queue , handles - thread might add additional tasks task queue, result. time thread has handle task unlimited - meaning thread works until task finished , never terminates before that.

what kind of problems (e.g. deadlocks) each following thread pool configurations susceptible to?

possible thread pool configurations i'm concerned with:
1) unbounded task queue bounded num. of threads
2) bounded task queue unbounded num. of threads
3) bounded task queue bounded num. of threads.
4) unbounded task queue unbounded num. of threads

also - thread has limited time handle each task, , forcibly terminated if doesn't finish task in time frame given. how change things?

if have bounded number of threads can experience deadlocks if task running on pool thread submits new task queue , waits task --- if there no free thread new task not run, , original task block, holding pool thread until new task can run. if end enough of these blocked tasks whole pool can deadlock.

this isn't helped bounding number of tasks, unless bound same number of threads --- once each thread doing can no longer submit new tasks.

what either (a) adding new threads when thread becomes blocked this, or (b) if pool thread task waiting task same pool thread switches running task being waited for.

if have unbounded number of threads have watch out oversubscription --- if have quad-core machine, submit 1000 tasks, , run 1000 threads these compete each other , slow down.

in practice, number of threads bounded large number os either due hard-coded number, or due memory constraints --- each thread needs new stack, can have many threads you've got memory stacks.

you can deadlock 2 tasks if wait each other, regardless of scheme use, unless start forcibly terminating tasks after time limit.

the problem forcibly terminating tasks twofold. firstly, need communicate code waiting task task terminated forcibly rather finished normally. secondly (and bigger issue) don't know state task in. might have owned lock, or other resources, , forcibly terminating task leak resources, , potentially leave application in bad state.


Comments

Popular posts from this blog

apache - Add omitted ? to URLs -

redirect - bbPress Forum - rewrite to wwww.mysite prohibits login -

php - How can I stop spam on my custom forum/blog? -