|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Announcements
Want a new Job?
Chapters
Services
Feature Zones
|
IntroductionSo, here I got again into another problem, and no search results gave me the answer I was looking for. The software in development was mostly using only one thread to run, but sometimes it could happen that concurrent threads start to run to update some parts of the software (this is a real-time software). That's where I discovered that some methods weren't thread safe. So what could be my solution? I decided to build an object which could be used to synchronize threads within one or more methods of another object (and possibly multiple objects). This object should respond to these criteria:
Thus was born the UsabilityThis sample is to test the capacity of theMethodSynchronizer.
The This object is really easy to use. The only thing you have to care of is where you declare your MoreI'm been using this sample to get up to 948 concurrent threads processed one after the other. After that, anOutOfMemoryException is thrown by the program.
The reason why I didn't create this object as a Singleton is because I wanted to have the possibility to lock different parts of my software at the same time but not together. So one is independent of the other. This object should be used when you have to lock for something that could take time. This is really useful when you get external access to your software, which could be anything like DB access, file, webpage, network,... and you only want ONE thread at a time to execute this code. I hope this could be more useful! If you have questions or comments, send them to thecodeproject@cints.net, or use the forum below.
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||