473,479 Members | 2,085 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Standard Threads vs Weightless Threads

Recently I read Charming Python: Implementing Weightless Threads
(http://www-128.ibm.com/developerwork.../l-pythrd.html) by
David D.

I'm not an authority on threading architectures so I'd like to ask the
following:

1)What is the difference (in terms of performance, scalability,[insert
relevant metric here]) between microthreads and "system" threads?

2)If microthreads really are superior then why aren't they the standard
Python implementation (or at least within the standard library)? (where
my assumption is that they are not the standard implementation and are
not contained within the standard library).

ps. I fear that my questions and assumptions about threading may be
rather naive. If they are, it's because I haven't yet done any
significant research.

Aug 1 '05 #1
2 1567
yoda wrote:
1)What is the difference (in terms of performance, scalability,[insert
relevant metric here]) between microthreads and "system" threads?
System-level threads are relatively heavyweight. They come with a full
call stack, and they take up some level of kernel resources [generally
less than a process]. In exchange, they're scheduled by the OS, with
the primary benefit (on uniprocessor systems) that if one thread
executes a blocking task (like IO writes) another thread will receive
CPU attention.

The primary disadvantage is that they're scheduled by the CPU. This
leads to the concurrency nightmare, where the developer needs to keep
track of what blocks of code (and data) need locks to prevent deadlock
and race conditions.

2)If microthreads really are superior then why aren't they the standard
Python implementation (or at least within the standard library)? (where
my assumption is that they are not the standard implementation and are
not contained within the standard library).


Microthreads are very different; they're entirely internal to the Python
process, and they're not seen at all by the operating system.
Scheduling is done explicitly by the microthread implementation --
multitasking is not preemptive, as with system threads.

They're not in the standard library because implementing microthreads
has thus far required a very large rewrite of the CPython architecture
-- see Stackless Python.
Aug 1 '05 #2
Christopher Subich <sp****************@block.subich.spam.com> writes:
the primary benefit (on uniprocessor systems) that if one thread
executes a blocking task (like IO writes) another thread will receive
CPU attention.
On multiprocessor systems, of course, the benefit is that threads can
run on separate CPUs. This could possibly be addressed by transparently
running one OS thread for each CPU, each containing a set of light
weight threads, and I hear people are thinking about that for Erlang
(light weight processes language extravaganza).

In the meanwhile, you can of course solve this by running two separate
instances of your program that communicates with each other somehow.

Another benefit is that you can have more threads than the limit the OS
imposes on you, and they can also be made quite a bit less memory
consuming. Some language implementations manages to deal with hundreds
of thousands, and in some cases even millions, of threads this way.
They're not in the standard library because implementing microthreads
has thus far required a very large rewrite of the CPython architecture
-- see Stackless Python.


Ruby's built-in threading also work something like this (if I understand
Stackless Python correctly).

(http://www.rubycentral.com/book/tut_threads.html)

Personally, though, I think treating treating light weight threads as
separate processes (which can only pass messages in between each other,
but do not share scope in any way), like Erlang, seems to make dealing
with massive concurrency easier.

--
Björn Lindström <bk**@stp.lingfil.uu.se>
Student of computational linguistics, Uppsala University, Sweden
Aug 1 '05 #3

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

Similar topics

20
2226
by: skoco | last post by:
Hello! Do you know when will be the new standard for c++ approved? And WHAT will be inside? Hope there will be some thread and synchro classes, text and XML parsing, new containers and other new...
85
4739
by: fermineutron | last post by:
Some compilers support __asm{ } statement which allows integration of C and raw assembly code. A while back I asked a question about such syntax and was told that __asm is not a part of a C...
22
2258
by: Chris Thomasson | last post by:
I am thinking about using this technique for all the "local" memory pools in a paticular multi-threaded allocator algorithm I invented. Some more info on that can be found here: ...
4
1649
by: dustin | last post by:
I've been hacking away on this PEP for a while, and there has been some related discussion on python-dev that went into the PEP: ...
126
6593
by: Dann Corbit | last post by:
Rather than create a new way of doing things: http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2008/n2497.html why not just pick up ACE into the existing standard:...
0
7027
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
6899
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
7019
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
6847
tracyyun
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...
1
4757
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...
0
4463
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...
0
2970
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
555
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
166
bsmnconsultancy
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...

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.