Re: Locking memory and multiple timers?
Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance
- From: Jon Skeet [C# MVP] <skeet@xxxxxxxxx>
- Date: Thu, 7 Sep 2006 22:34:17 +0100
FredC <FredC@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote:
I have an application that uses mulitple timers. Each of the timer event
handlers manipulate a common array of data.
I'm getting Null refererance errors - should I put a lock on the array when
I change a value?
Could you post a short but complete program which demonstrates the
problem?
See
http://www.pobox.com/~skeet/csharp/complete.html for details of
what I mean by that.
In general though, yes - you need to obtain a lock (on something, see
below) if you're going to access/change shared data.
As well, should I lock the array when I only want to read a value?
I wouldn't lock the array, but a separate locking object. See
http://www.pobox.com/~skeet/csharp/threads/lockchoice.shtml
--
Jon Skeet - <skeet@xxxxxxxxx>
http://www.pobox.com/~skeet Blog:
http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
.
Relevant Pages
- Re: how to read dynamic data structures from the kernel (was Re: reading routing table)
... could give us individual entries of the data structure on each call, ... steps for any given kernel subsystem -- we have data structures, ... bumping the references and adding pointers to the array. ... the global locks, and proceed lock, externalize, unlock, and copyout each ... (freebsd-net) - Re: [PATCHv3] drivers/misc: Altera active serial implementation
... I use the minor field to lookup the drvdata pointer in get_as_dev, ... I do this because I have no access to the 'struct ... Get rid of the array and minor lookup, ... I was thinking that the device lock which is being held during the .probe ... (Linux-Kernel) - Re: Suggestion for review: a taxonomy of thread safety
... > as regards their behavior when run in multiple threads, ... > lock ... for example you have an array of objects and you want to implement the ... from every entry of the array and fills it into a caller ... (comp.programming) - Re: MFC threads and critical section
... secondary threads. ... So when first thread is accessing array, ... the wheel by writing my own code for synchronization since Windows API ... can acquire the lock, and if the lock can't be acquired, it spins for a brief period ... (microsoft.public.vc.mfc) - Re: cuncurrent access to file on network
... "Fabio R." ... > It works very fine, the array contains userid, pageid and the lock datetime: ... > page while other pending lock are removed if older than session timeout. ... >>> user can only read the file after the first user has finished the task? ... (microsoft.public.dotnet.framework.aspnet) |
|