Hi there,
I need to create an atomic section in Python code i.e. there is no
context switch to any other thread during the running of that piece of
code. Would would do the trick?
thanks, 6 5467
Ahmad Humayun wrote:
I need to create an atomic section in Python code i.e. there is no
context switch to any other thread during the running of that piece of
code. Would would do the trick?
use a lock, and make sure that anyone that needs access to the shared
state you're manipulating in that section uses the same lock.
lock = threading.Lock( ) # or RLock() etc [1]
with lock:
section
this only works if everyone honors the lock, of course; there's no way
in Python to lock out non-cooperating external threads.
</F>
1) see http://effbot.org/zone/thread-synchronization.htm
On Sep 5, 1:59*pm, Fredrik Lundh <fred...@python ware.comwrote:
Ahmad Humayun wrote:
I need to create an atomic section in Python code i.e. there is no
context switch to any other thread during the running of that piece of
code. Would would do the trick?
use a lock, and make sure that anyone that needs access to the shared
state you're manipulating in that section uses the same lock.
* * *lock = threading.Lock( ) # or RLock() etc [1]
* * *with lock:
* * * * *section
this only works if everyone honors the lock, of course; there's no way
in Python to lock out non-cooperating external threads.
</F>
1) seehttp://effbot.org/zone/thread-synchronization .htm
Thats true, but this will ensure mutual exclusion; not atomicity
thanks again,
Ahmad Humayun schrieb:
On Sep 5, 1:59 pm, Fredrik Lundh <fred...@python ware.comwrote:
>Ahmad Humayun wrote:
>>I need to create an atomic section in Python code i.e. there is no context switch to any other thread during the running of that piece of code. Would would do the trick?
use a lock, and make sure that anyone that needs access to the shared state you're manipulating in that section uses the same lock.
lock = threading.Lock( ) # or RLock() etc [1]
with lock: section
this only works if everyone honors the lock, of course; there's no way in Python to lock out non-cooperating external threads.
</F>
1) seehttp://effbot.org/zone/thread-synchronization .htm
Thats true, but this will ensure mutual exclusion; not atomicity
AFAIC that kind of mutual exclusion is what atomicity is about. What
else do you expect to happen?
Diez
On Sep 5, 10:59*am, Fredrik Lundh <fred...@python ware.comwrote:
>
1) seehttp://effbot.org/zone/thread-synchronization .htm
The page you link here is WAYS better than the standard documentation
of the threading module.
Generally speaking, the effbot zone contains a lot of improvements
over the standard docs
which are lacking in various areas.
I have always wondered why they are kept separated. Wouldn't be nice
to have the standard
docs integrated with the effbot docs? Are there plans in this sense
and if not, why not?
Michele Simionato
Michele Simionato wrote:
The page you link here is WAYS better than the standard documentation
of the threading module.
Generally speaking, the effbot zone contains a lot of improvements
over the standard docs which are lacking in various areas.
I have always wondered why they are kept separated. Wouldn't be nice
to have the standard
docs integrated with the effbot docs? Are there plans in this sense
and if not, why not?
There are tons of great supplementary material out there, on blogs,
personal documentation collections (such as effbot.org), cookbook sites,
etc. I don't think all that material absolutely must be posted to
python.org, but Python users would definitely benefit from improved
cross-linking.
And this is, of course, something I've lobbied for many times, e.g. http://mail.python.org/pipermail/pyt...ay/322224.html http://mail.python.org/pipermail/pyt...er/355625.html http://effbot.org/zone/idea-seealso.htm
but I haven't yet figured out how to get something to happen [1]. All
ideas are welcome.
</F>
1) Well, I guess the new Sphinx tool might have gotten some inspiration
by my work in this domain: http://mail.python.org/pipermail/pyt...ry/059978.html
and Andrew Kuchling did some preliminary work for the old Latex work flow: http://svn.python.org/view/sandbox/trunk/seealso/
Diez B. Roggisch wrote:
AFAIC that kind of mutual exclusion is what atomicity is about. What
else do you expect to happen?
sounds like he wants/needs non-cooperative, mandatory locking.
</F> This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Paul Moore |
last post by:
I can't find anything which spells this out in the manuals. I guess
that, at some level, the answer is "a single bytecode operation", but
I'm not sure that explains it for me.
This thought was triggered by a comment on the Python Cookbook site,
which basically said that it was OK to do
tss = {}
...
id = thread.get_ident()
tss = {}
|
by: Glenn Kasten |
last post by:
I am wondering which operations in Python
are guaranteed to be atomic in the presence
of multi-threading. In particular, are assignment
and reading of a dictionary entry atomic?
For example, initially:
dictionary = {}
dictionary = old_value
Then thread 1 does:
v = dictionary
And thread 2 does:
|
by: Shayan |
last post by:
Is there a boolean flag that can be set atomically without needing to
wrap it in a mutex? This flag will be checked constantly by multiple
threads so I don't really want to deal with the overhead of mutexes or
semaphores. Thanks.
Shayan
|
by: Pegboy |
last post by:
What does it mean to make a function atomic?
Something I read on it wasn't very clear, but made me think that I needed to
disable interrupts for that function. Whether that's the case or not, how
would I make the following function atomic?
int Test;
int GetTestValue( void )
{
|
by: blackstreetcat |
last post by:
consider this code :
int i; //gobal var
Thread1:
i=some value;
Thread2:
if (i==2) dosomething();
else dosomethingelse();
| |
by: Ole Nielsby |
last post by:
I need to implement reference counting in a class hierarch,
in a thread safe manner. (The classes are umanaged but I
might want to compile them with the /clr option.)
Some of the objects - atoms - are registered in a global hash
table - let's call it an atom table. When an atom refernce
count reaches zero, the atom is removed from the table.
The catch is, after an atom has been counted down, another
thread might find it in the atom...
|
by: Ark |
last post by:
Consider
static T foo;
..............
T get_foo(void) { return foo; }
In a multi-threaded (or -tasked) environment, I need to ensure that I
get_foo() grabs T atomically (e.g. is not preempted while accessing foo).
Are there types T for which atomic fetch /guaranteed/ portably? Does the
|
by: Dave Stallard |
last post by:
Pardon if this is the wrong newsgroup for this question, and/or if this
question is naive.
I have a multi-threaded Windows application in which certain
variables/object fields are shared: one thread may write the variable,
and the other thread read it. The variables in question may have int or
int* types. Question: Is it safe to do this? Or is it possible a read
that happens at the same time as a write may retrieve a scrambled value,...
|
by: Freedom fighter |
last post by:
Hello,
Is a singleton class the same as an atomic class? I know that a singleton class
can only be instantiated once, but does that concept apply to an atomic class?
Thank you.
|
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
| |
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |