473,387 Members | 1,431 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.

Synchronization bool shared fields

Is synchronization for bool shared fields required in multithreaded
application?

Is there a cases when for example changing value from true to false in one
thread, when another thread is reading this field, will lead to true value
in this field?
Aug 26 '05 #1
3 1356
Vladimir <xo***@tut.by> wrote:
Is synchronization for bool shared fields required in multithreaded
application?
Yes. It should either be volatile, or you should lock access.
Is there a cases when for example changing value from true to false in one
thread, when another thread is reading this field, will lead to true value
in this field?


It won't stop the first thread from actually writing the change out,
but you may not see the change when reading in the second thread unless
you have a lock or make the flag volatile.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Aug 26 '05 #2
>> Is synchronization for bool shared fields required in multithreaded
application?


Yes. It should either be volatile, or you should lock access.
Is there a cases when for example changing value from true to false in
one
thread, when another thread is reading this field, will lead to true
value
in this field?


It won't stop the first thread from actually writing the change out,
but you may not see the change when reading in the second thread unless
you have a lock or make the flag volatile.


Thanks...

But wait a minute...
I'm using some classes from two threads (time to time, but always not in one
moment -
when some volatile bool variable is true, i'm using them from first thread,
when false
- from second). What about shared data in this objects? Can the new state be
invisible
from another thread?
Aug 26 '05 #3
Vladimir <xo***@tut.by> wrote:
Thanks...

But wait a minute... I'm using some classes from two threads (time to
time, but always not in one moment - when some volatile bool variable
is true, i'm using them from first thread, when false - from second).
What about shared data in this objects? Can the new state be
invisible from another thread?


Yes, if you don't have any locking in place.
See http://www.pobox.com/~skeet/csharp/t...latility.shtml

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Aug 26 '05 #4

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

Similar topics

0
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...
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...
10
by: Teis Draiby | last post by:
In an application manipulating streaming video and 3D stuff I want to implement mutithreading to ensure a decent UI response time. Since my application is very speed critical I want to use the...
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,...
3
by: Vladimir | last post by:
Is synchronization for bool shared fields required in multithreaded application? Is there a cases when for example changing value from true to false in one thread, when another thread is reading...
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...
1
by: Blake | last post by:
Heya Group. I am hoping that someone can help me understand how to use Synclock properly. I am a tad confused. I have a class that is instanced on multple threadpool threads, and uses shared...
7
by: atlaste | last post by:
Hi, I have two different things I'd like to discuss here. Both are about cross-process synchronization of shared resources. The resources that are shared are: (1) an object writing to a file and...
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: 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
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...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.