473,395 Members | 1,456 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,395 software developers and data experts.

[Synchronization] Atrribute and thread synchro question

Hello everyone.
I've got question you may consider simple. Im rather new to C#, and I am not quiet sure about one thing. I've found somewhere, that one of ways of synchronizing access of few threads to one object is by using [Synchronization] attribute and ContextBoundObject class derivance. I am not sure how does it work. I mean .. in C/C++, where object of some class may contain OBJECTS of another class, using such an attribute (if it would be possible in C/C++) is rather easy to understand, because object of a class containing PHYSICAL OBJECTS of another class could be considered as a big can in memory. In C# object of one class contains REFERENCES to objects of another class. Now considering sample code :

Expand|Select|Wrap|Line Numbers
  1.  
  2. [Synchronization]
  3. class X : ContextBoundObject
  4. {
  5.     private DataSet ds;
  6.     public X(..) {...}
  7.     ...
  8.     ...
  9.  
  10.    public DataTable MainTable
  11.    {
  12.       get
  13.        {
  14.              return ds.Tables["maintable"];
  15.        }
  16.    }
  17.    ...
  18.    ...
  19. }
  20.  
  21. class Program
  22. {
  23. ...
  24.     X x = new X(...);
  25. ...
  26. }
  27.  
Now.. MainTable is returning reference to One of tables inside of DataSet. Now
is access to MainTable also synchronized ? I mean.. if one thread is modifying MainTable(which should be "part" of object x of class X ) then no other threads can access x.MainTable, right ? And what in case, when reference X.ds.Tables["maintable"] will change ( new DataTable will be assigned ) ?

I'm not sure if anything what i wrote is understandable, but if anyone gets what i meant, please help :) Thanks a lot.
Sep 12 '08 #1
1 1156
PRR
750 Expert 512MB
If you could post more code .. its will be more clear... in case you have a function/s where multiple threads are accessing and you need to "lock it " there are various ways of doin it..
Check this

Read more abt threading ...
Sep 15 '08 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

5
by: Cyrus | last post by:
I have a question regarding synchronization across multiple threads for a Hashtable. Currently I have a Threadpool that is creating worker threads based on requests to read/write to a hashtable....
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...
1
by: Bill Davidson | last post by:
(RESEND: I added a little more code to the sample for clarity) Hello All: I've got a question about synchronization requiremements in a C# worker thread procedure that, among other things,...
4
by: scott | last post by:
hi all, Thx to any one that can offer me help, it will be much appreciated. iv got a multithreaded program and need to use thread synchronization. The synchronization does not have to...
5
by: fei.liu | last post by:
Hello, in the application I am developing, I am having trouble to synchronize event triggered actions using 'lock(ob){...};' technique. Here is a outline of my code: class C{ int x = 0; public...
12
by: emma_middlebrook | last post by:
Hi Say you had N threads doing some jobs (not from a shared queue or anything like that, they each know how to do their own set of jobs in a self-contained way). How can you coordinate them so...
5
by: Tony Gravagno | last post by:
I have a class that instantiates two Timer objects that fire at different intervals. My class can be instantiated within a Windows Form or from a Windows Service. Actions performed by one of the...
0
by: sundman.anders | last post by:
Hi all! I have a question about thread synchronization and c++ streams (iostreams, stringstreams, etc). When optimizing a program for a multicore processor I found that stringstream was causing...
3
by: CKKwan | last post by:
Dear All, Can synchronize a class, any function is called and the entire class is locked. Can synchronize a method What if I need to Lock a class only when specific method is call?
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

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.