I have a program that involves receiving a packet from a network on one thread, then notifying other threads that the packet was received. My current approach uses Thread.Interrupt, which seems to be a bit slow when transferring huge amounts of data. Would it be faster to use “lock” to avoid using to many interrupts, or is a lock really just calling Interrupt() in its implementation?
Share
I don’t understand why you would use
Thread.Interruptrather than some more traditional signalling method to notify waiting threads that data is received.Thread.Interruptrequires the target thread to be in a wait state anyway, so why not just add an object that you can signal to the target thread’s wait logic, and use that to kick it for new data?lockis used to protect critical code or data from execution by other threads and is ill-suited as a mechanism for inter-thread active signalling.Use
WaitOneorWaitAllon suitable object(s) instead of either.System.Collections.Concurrentin .Net 4 also provides excellent means for queueing new data to a pol of target threads, and other possible approaches to your problem.