reticent
reticent

Reputation: 1669

How to test thread safety of adding to a hashtable?

We're using a hashtable to store sessions in a web service. I want to test thread safety of adding to this session. I wrote a Console App which generates lots of threads and adds to this session. But I am neither getting an exception nor losing any data. Am I doing anything wrong or isn't this much of operation a threat to hashtable?!

Upvotes: 1

Views: 334

Answers (2)

Meh
Meh

Reputation: 7176

I had the same problem.

The only way I know how to test this is by slowly reviewing all the possible thread/lock interaction in the source code or on a piece of paper.

A long time ago I had an app with 8 threads interacting between them, and it crashed about once time a week of constant use. After a few of these crashes I started to suspect a threading issue. So I managed to simplify a lot the locking code, and then I proved on a piece of paper that all the possible thread/lock interactions were safe. The issue disappeared.

Upvotes: 0

Steve Townsend
Steve Townsend

Reputation: 54168

I'm not sure why you re going to such trouble to verify that concurrent writes to Hashtable are going to crash your app.

Even if your test app runs safely for a long time, you should not deploy code that does not protect your Hashtable from writes that are concurrent with other read or write operations.

10000 threads is a very large number, by the way - I hope your production app does not plan on using this many.

Upvotes: 2

Related Questions