Say we have std::map Sockets map, and it's a multithreaded application. There will be more than one threads accessing sockets in the map for sending socket data, meanwhile there will be only one thread accessing sockets in the map for receiving data and this thread will also delete the SocketInfo* if the remote end closes.
In the above situation, can we use the read-write lock (pthread_rwlock_t) to synchronize the threads? If yes, do we have more benefits than pthread_mutex_t?
Steve
[PSEUDO CODE]
class CSocketIO {
std::map<int, SocketInfo*> m_Sockets; //socket value and socket info
pthread_t m_ReadingSocketThreads; // for reading socket data
};
class CSession {
void SendOutNetworkPackets(); //access sockets for sending sock data
pthread_t m_WorkerThread; // do jobs and send sock data
};
class CSomeClass {
void SendOutNetworkPackets(); // also access sockets
pthread_t m_WorkerThread; // do jobs and send sock data
};