开发者

When exactly would you want to use a thread-safe stack?

开发者 https://www.devze.com 2023-01-23 20:03 出处:网络
I came across this question and was curious 开发者_运维问答under what real life situations you would actually want to use a stack from multiple threads, as opposed to a FIFO queue, or a priority queue

I came across this question and was curious 开发者_运维问答under what real life situations you would actually want to use a stack from multiple threads, as opposed to a FIFO queue, or a priority queue. It just seems very counter intuitive to me that the LIFO property is ever appropriate when being used across several threads. You really would have no guarantee about what you are getting off the stack, other than stuff that was put there pretty recently. Wouldn't this tend to greatly starve out older things in the stack/queue?


I can conceive that this might be useful in a situation where responding to most-recently arrived work was deemed more useful. Kind of a 'high-priority interrupt' model, with older items to be examined and processed as time permits.

I can imagine implementing a Stack Overflow reputation-gathering bot that would work this way. Single-threaded input takes a feed of new questions onto a stack - a thread pool pops and quickly responds to the recent ones, and examines and answers older ones if not already having an accepted answer and not more viable reputation opportunities via new questions arriving.

0

精彩评论

暂无评论...
验证码 换一张
取 消