Just a quick question on mutexes (looked up the correct plural form, this is as close as it comes)
When I use a mutex, how would I go about checking if it's locked? I don't want to lock it when I check, I just want to see the state.
(reason being): I have a vector of pairs of sockets or partners of connected strangers and I need to check the vector every second or half second and I will have to change the sockets around only occasionally so I really don't need to lock the whole vector to check just a single member. (I was thinking of having a vector of mutexes but that just seemed silly)
On a side note, what stl container would be best for a pair of ints, in which the key to eachother is the partner's int?
Couldn't really tell as I don't know what mutexes you are talking about (Windows ones?). Besides, I think that locking the whole vector seems to be reasonable (although I may be wrong as I don't really know exactly what your program is doing).
As for the container, I believe you need fast searching by either the first or the second element of a pair. No stl container supports that. However, there is a question: how many pairs you will typically have? If it is not a significant number then maybe even a slow search algorithm (iterating a list or vector) will be sufficient.
Regarding the container you could try Boost intrusive set for example. I am not very familiar with it, but I sure can't think of appropriate STL solution.
@abramus & coder777
Well the program is a server serving pairs of anonymous clients, so it is time sensitive, initially...
double edit: sorry didn't mention what the pairs of ints are, they are simple pairs of SOCKET (or uint)
@simeonz
I just figured the standard library would be a good way to go, i'll look into boost intrusive.
---
When you say a map is sorted, it's only sorted when an object is added or removed correct?
And I looked into the documentation it mentioned a multimap, how efficient would that solution be compared to a simple vector solution (a vector of structs which hold the key to the pair's vector member)?
edit: i'm going to do a little testing on both solutions and i'll let you know what I find, I would still like to know what your preferred method would be