Are arrays multi thread safe?

Im working on a project like this:

-An app will be collecting data from sensors (sometimes once per second).
-The data is shown on screen until new data is readed
-The data will be saved to a local SQLite database, but
-The data also will be send to a server (each entry needs to be in a POST).

So, my idea, In the Main thread, receive data, prent to scren, save to DB and insert it on a array.

In a separate thread, a loop to send the data syncronously with HTTPSecureSocket, on success, pop the item, write to the DB as Item sended and send next item.

To be conssidered, internet sometimes could fail or be very slow.

So, It is safe to insert on an array and pop in separate threads?

What would be the best opproach for this situation?


There is nothing inherent in an array to make it thread safe… you need to provide the mechanism to do this. On the other hand threads in XOJO are cooperative so you might just get away with it, but I would not relay on this.

Personally I split this kind of thing up - a service collecting the data and a client serving it up. Then you can use more cores and even if the client crashes for some reason the data collection goes on…

On critical systems I also add an ‘angel’ to watch over the service and restart it if it should fall over.