X
X
xozzslip2016-09-30 22:47:01
Python
xozzslip, 2016-09-30 22:47:01

How to implement resource locking for all threads except one (again)?

I 've asked a similar question before, but this time it's a bit more complicated.
There is a table that stores tokens for making requests to vk api. It is necessary to make sure that the same token cannot be used simultaneously by two different threads. If a thread needed a token, it chose from some list of available ones or waited if there were no free tokens.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
N
nirvimel, 2016-09-30
@xozzslip

To do this, it is convenient to use the queue ( howto ).
The scheme will work fine and not cause collisions when the number of threads is many times greater than the number of tokens, but only if the tokens are captured for a short time and quickly released, otherwise most of the threads will hang forever waiting for free tokens.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question