473,320 Members | 1,974 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

Thread Synchronization and method parameters

This is probably a very simple question but I just want to make sure.
If I have three threads, all of which use their own class scope copy
of an object. Now, say I reuse this object for each iteration in each
thread, so I have to clean it. I have one method that takes in as an
argument one of these objects and zero's out the needed fields. I
don't need to lock this method right? Each thread will have it's own
copy, and because they're using their own variable it won't make a
difference? Am I good on this?

Nov 9 '07 #1
2 1100
The way you describe it, it should be fine,. As long as each instance
is private to a single thread, then yes: you're pretty-much good to
go. If the threads are started with an anonymous method, you might
have to watch out for captured variables; ditto any static fields
(although a static emthod that doesn't share state is fine); and there
are a few other gotchas in complex scenarieos - but in the general
case it sounds fine.

Marc

Nov 9 '07 #2
On Nov 9, 8:07 am, Marc Gravell <marc.grav...@gmail.comwrote:
The way you describe it, it should be fine,. As long as each instance
is private to a single thread, then yes: you're pretty-much good to
go. If the threads are started with an anonymous method, you might
have to watch out for captured variables; ditto any static fields
(although a static emthod that doesn't share state is fine); and there
are a few other gotchas in complex scenarieos - but in the general
case it sounds fine.

Marc
THanks yeah, I thought it would be OK. The threads are actually all
coming from async callbacks
from who knows where. But I figured I would take advantage of the
events and do some work on their threads since I'm not concerned with
bogging them down. But yes, all three instances are slotted for use
by only one thread.

Nov 9 '07 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Steven Brown | last post by:
I'm trying to figure out how to safely use .NET events/delegates in a thread-safe class. There are a couple problems. One is that the standard "if(EventName != null) EventName(...);" call can...
31
by: AlexeiOst | last post by:
Everywhere in documentation there are recommendations to use threads from thread pooling for relatively short tasks. As I understand, fetching a page or multiple pages (sometimes up to 50 but not...
7
by: Ivan | last post by:
Hi I have following problem: I'm creating two threads who are performing some tasks. When one thread finished I would like to restart her again (e.g. new job). Following example demonstrates...
7
by: Ivan | last post by:
Hi there My work on threads continues with more or less success. Here is what I'm trying to do: Class JobAgent is incharged for some tasks and when it's called it starts thread which performs...
5
by: Bill Davidson | last post by:
Hello All: I've got a question about synchronization requiremements in a C# worker thread procedure that, among other things, sinks events from outside sources. I realize the worker thread will...
20
by: Bob Day | last post by:
Using VS 2003, VB, MSDE... There are two threads, A & B, that continously run and are started by Sub Main. They instantiationsl of identical code. Thread A handles call activity on telephone...
2
by: Aaron Cutlip | last post by:
I have been looking all over and have seen many possible ways to create a Syncronized Shared Function in VB.NET, but I would like some advice that will make my life easier. Given the following...
6
by: HolyShea | last post by:
All, Not sure if this is possible or not - I've created a class which performs an asynchronous operation and provides notification when the operation is complete. I'd like the notification to be...
9
by: RvGrah | last post by:
I'm completely new to using background threading, though I have downloaded and run through several samples and understood how they worked. My question is: I have an app whose primary form...
16
by: Paul Schwann | last post by:
Hi group, I am relatively new to C# (although I have a lot of programming excperience in other languages like Java and C). Currently I am searching for a solution to this problem: Suppose you...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.