Skip to content

Tips for Thread Safety? #32

Answered by nvictus
suhailrehman asked this question in Q&A
Discussion options

You must be logged in to vote

Very late response, but you are right that this is not a thread-safe implementation.

However, if you take a look at the standard library queue module, you can see that the Queue base class implements all of the locking required for thread safety. It should be possible to derive something similar to the stdlib queue.PriorityQueue that wraps a pqdict. To expose extra functionality like looking up an item by key or modifying a priority, you would have to add additional methods that acquire locks similar to the implementation of Queue.get.

It would make a nice recipe to add to the examples.

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by nvictus
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants
Converted from issue

This discussion was converted from issue #15 on September 08, 2024 18:32.