Non-Blocking Manufacturer and Consumer Using .NET 2.0

In our scenario

  • the consumer takes at least half a second to complete the process cycle (against the row in the data table).
  • The manufacturer produces at least 8 elements per second (do not worry, we do not mind the duration of consumption).
  • shared data is just a data table.
  • we should not ask the producer to wait (since this is a server, and we do not want him to wait for this)

How can we achieve the above without locking the data table at all (since we don’t want the producer to wait somehow).

We cannot use .NET 4.0 yet in our organization.

+3
source share
3 answers

/ "/ ". , .

, , .NET .

+1

, .

, 8 ... 4 , , .

, , , (16 ), , .

0

, DataTable . , . , . , DataRow DataTable.

So, what would I do, get a lock from the manufacturer, add a new line and release the lock. Then in the conumser you will get the same lock, copy the data contained in DataRow, into a separate data structure, and then immediately release the lock. Now you can work with copied data without synchronization mechanisms, since they are isolated. After you have completed the operation on it, you will get the lock again, merge the changes back into DataRow, and then release the lock and start the process again.

0
source

All Articles