473,398 Members | 2,368 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,398 software developers and data experts.

What does Thread safe mean?

Some of the classes in the framework are marked as thread-safe in the
documentation. In particular the docs say the following:
"Any public static (*Shared* in Visual Basic) members of this type are
thread safe. Any instance members are not guaranteed to be thread safe."

What exactly does this mean? Does this mean that if I call a shared
method from 2 different threads, nothing whacky will happen?
Also when it says that instance members are not guaranteed to be thread
safe, does that mean that I can't call an instance member from 2 threads
simultaneously?

In addition, the docs about the Queue class say the following:

"To guarantee the thread safety of the *Queue*, all operations must be
done through the wrapper returned by the Synchronized
<frlrfsystemcollectionsqueueclasssynchronizedtopic .htm> method."

Does this mean that I can call any member of the class from any number
of threads and have it be thread-safe? In other words, can I add/remove
objects to/from the queue from various threads and have everything be
hunky-dory?
Nov 16 '05 #1
1 8721
Frank,

See inline.
Some of the classes in the framework are marked as thread-safe in the
documentation. In particular the docs say the following:
"Any public static (*Shared* in Visual Basic) members of this type are
thread safe. Any instance members are not guaranteed to be thread safe."

What exactly does this mean? Does this mean that if I call a shared
method from 2 different threads, nothing whacky will happen?
Yes, that is exactly what it means.
Also when it says that instance members are not guaranteed to be thread
safe, does that mean that I can't call an instance member from 2 threads
simultaneously?
Well, you could, but you would get "wacky" results, as you say. They
were not coded with thread-safety in mind, and you would have to handle
access to those objects if you were to use them from separate threads.

In addition, the docs about the Queue class say the following:

"To guarantee the thread safety of the *Queue*, all operations must be
done through the wrapper returned by the Synchronized
<frlrfsystemcollectionsqueueclasssynchronizedtopic .htm> method."

Does this mean that I can call any member of the class from any number of
threads and have it be thread-safe? In other words, can I add/remove
objects to/from the queue from various threads and have everything be
hunky-dory?


Yes, but only if you get the wrapper that is returned from the
Synchronized method.

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com
Nov 16 '05 #2

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

Similar topics

3
by: Frazer | last post by:
Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.? can anyone illustrate with an example.
9
by: Andy Chang | last post by:
Hi, If I have this function void DoSomething(int& index) { ::Sleep(10000); DoSomethingWith(index); } Is the variable index thread safe? Meaning that if I call this from two
11
by: dee | last post by:
OleDbCommand class like many .NET classes has the following description in its help file: "Thread Safety Any public static (Shared in Visual Basic) members of this type are safe for...
4
by: John Pugh | last post by:
I'm learning VB.NET (I barely have a grip on classes, inheritance and polymorphism though), and I was looking at some of the terms on the MSDN site. What does it mean if something is "thread...
3
by: Ant | last post by:
Hi, I'm wondering what this exactly means when I see it describing class in MSDN. "Any instance members are not guaranteed to be thread safe." What does this mean exactly & how could an "un...
18
by: cj | last post by:
members of this type are safe for multithreaded operations. Instance members are not guaranteed to be thread-safe. I'm under the impression before you can use a class you have to make an...
8
by: ecir.hana | last post by:
Dear list, maybe I'm overlooking something obvious or this is not possible at all or I don't know. Please, consider the following code: ## insert here anything you like def changer():
10
by: _mario.lat | last post by:
hallo, what does it means "the function is not thread-safe"? thak you in advance, Mario.
167
by: darren | last post by:
Hi I have to write a multi-threaded program. I decided to take an OO approach to it. I had the idea to wrap up all of the thread functions in a mix-in class called Threadable. Then when an...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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
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...
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...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.