Multithreaded difficult, try multi-server multi-threaded!

By | September 24, 2007

Any developer of multithreaded systems will know the following problem. You have a nice program that is working on a shared memory and shared data. Now you don’t want to get dirty reads, or worse yet dirty writes. So you build in techniques to prevent this. But what if you have the same problem accross multiple fisical computers.

You could try using semaphores, a technique used to synchronize multiple threads in one system. This means you enable a flag to indicate something is doing a critical process that should not be interrupted. Another way could be to set a generic flag that indicates what state the information is in.

For example if you use a file you could use the following statuses:

  1. Some application is reading the data for analysis
  2. An application is writing to the file
  3. An application is purging processed data

Pending on what status is set a computer can do some work or not.  If the flag is set to 1 that means another application should not purge data nor should it append data. As this could lead to incomplete information.

Doing so accross multiple computers means that you have to build a messaging system of sorts. If you’re on one network and running Windows you could use windows messaging services for this.

But if you’re on the internet or on different physical networks you’re going to have to use something like SOAP or a database to achieve the same result. Using SOAP means you will have to build a PoolManager that will store the status for you. And where applications can ask what the current status is.

None of the above is simple, and some are very slow (like SOAP calls). So try out what ever works best for you.

Leave a Reply