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

Thread safety for initializers and linked list assignments?

I have a class that has no ancestors and only static data members of type
string and ListDictionary. I am not allowed to use a static constructor.

Here is the code:

class sql{

private static string LogSource=abc();

// Hold a list of databases and their configuration values
private static ListDictionary DBList = Init();

Jun 27 '08 #1
1 1521
Siegfried Heintze <a-******@microsoft.comwrote:
I have a class that has no ancestors and only static data members of type
string and ListDictionary. I am not allowed to use a static constructor.
Using a static constructor would just give more definite guarantees
about *exactly* when it would be called. The normal guarantee around
"called only once" applies, and that will happen at some point before
the first use of any static field in the type.

<snip>
1. Is the initializer for LogSource (function abc) guaranteed to
execute before Init?
Yes.
2. Is the assignment part of the call to the initializer for DBList
thread safe?
Yes.
3. Presently, the implementation of function init does everything
inside a lock statement. Is this lock statement superfluous?
Assuming it doesn't touch anything else, yes.

--
Jon Skeet - <sk***@pobox.com>
Web site: http://www.pobox.com/~skeet
Blog: http://www.msmvps.com/jon.skeet
C# in Depth: http://csharpindepth.com
Jun 27 '08 #2

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

Similar topics

5
by: MetalOne | last post by:
Are atomic operations thread safe in Python? Can immutable objects, such as, strings, be created on one thread and then accessed by another thread, without using locks? Such operations are not...
5
by: Roman Suzi | last post by:
(this is a repost with an addition - probably noone noticed my message first time) Hi! Just to be sure, is email package of Python 2.3 thread-safe or not (to use, for example, in...
11
by: C++fan | last post by:
Suppose that I define the following class: class example_class{ public: example_class(); void funtion_1(); void function_2(); protected:
2
by: Dave | last post by:
Hello all, I am creating a linked list implementation which will be used in a number of contexts. As a result, I am defining its value node as type (void *). I hope to pass something in to its...
19
by: RAJASEKHAR KONDABALA | last post by:
Hi, Does anybody know what the fastest way is to "search for a value in a singly-linked list from its tail" as oposed to its head? I am talking about a non-circular singly-linked list, i.e.,...
5
by: John N. | last post by:
Hi All, Here I have a linked list each containing a char and is double linked. Then I have a pointer to an item in that list which is the current insertion point. In this funtion, the user...
12
by: Eugen J. Sobchenko | last post by:
Hi! I'm writing function which swaps two arbitrary elements of double-linked list. References to the next element of list must be unique or NULL (even during swap procedure), the same condition...
17
by: Rainer Queck | last post by:
Hi NG, one more question about thread safety of generic lists. Let's assume a generic list: List<MyTyp> aList = new List<MyType>(); Would it be a problem if one thread removes elements from...
1
by: r035198x | last post by:
Inspiration Inspired by a post by Jos in the Java forum, I have put together a little article on class initializers. Initializers are indeed underutilized by most Java programmers. Once the Java...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
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: 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
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...

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.