I am designing a multi-threaded piece of code that includes a part where several sensors are queried (through socket), and their data is stored first in a Vector and subsequently written into a DB.
The entire process is time sensitive since the each sensor updates every few seconds with a new data. If the data is not retrieved in time, it is lost. Currently, I have a Vector of (Custom Sensor Data) class that stores the information obtained from and about each of the sensors.
The plan was to open a thread for each sensor (say, 40-50 in total, but do not want to limit by number in case more sensors are added later) and have it access and fill a particular (set by the index of Vector) cell of the Vector.
Is such operation on the Vector allowed and prudent? Also, knowing the peculiarities of TCP/IP sockets, am I likely to drastically speed up the process by introducing threads (as opposed to, say, running everything in a single thread)? Is there a better or more elegant way of doing this?