Can concurrent code (threads, distributed computing, etc.) be directly ported to single-threaded/non-networked platforms?

Take an arbitrary “perfect” multi-threaded program, on an arbitrary multi-threaded platform, using an arbitrary programming language.

Assuming that this “perfect” multi-threaded program:

  • is flawless in terms of race conditions
  • handles shared memory perfectly
  • may/may not use a locking mechanism (thread suspension or mutexes fall into this category)
  • has no unforeseen bugs (100% bug free)
  • uses no complicated language/system specific constructs that cannot be translated to another system under any circumstance

and assuming that this arbitrary platform

  • is/isn’t POSIX compliant (doesn’t matter)
  • uses a familiar threading model
  • doesn’t turn the locking mechanism into a whirlwind of voodoo spaghetti code (arguably)

and assuming this arbitrary language

  • doesn’t use any domain-specific threading constructs (such as Java’s synchronized keyword)
  • is platform agnostic at the very core (such as C and variants)
  • can be cross-compiled to many different architectures/platforms (isn’t limited to the platform its on)

can the code inherently be implemented in such a way that it runs as expected on a single-threaded platform?

For instance, in lieu of threads the single-threaded platform uses a co-routine-like model to simulate threads. Is there a fundamental design flaw with such concepts that would inhibit the ability to run the program in this thread-absent/thread-emulated environment?

The answer to this broad question is very platform-specific, but as I alluded to earlier I’m interested in whether or not there is an inherent proprietariness with multi-threading that makes them impossible to port to non-threaded environments.


Additionally (and more concretely), are there any specific, mainstream platforms/architectures that wouldn’t allow such a scenario to occur?

4

There are two main types of multitasking:

  • Cooperative – where code explicitly calls a function to say “do something else now”
  • Pre-emptive – where the threading system automatically stops one thread to allow another to run

These days, most multitasking code is pre-emptive, although event driven code (e.g. Twisted) is cooperative. I do remember using Visual Basic in the 90s and within long running jobs, having to put in calls to DoEvents. That was cooperative multitasking.

The distinction matters, because if your app is coded for pre-emptive multitasking, you can’t switch it to cooperative, unless you make substantial modifications. In that sense, the answer to your question is no – you can’t take a pre-emptive threaded program and make it run cooperatively using coroutines.

However, if your operating system provides a fine-grained alarm function, it is usually possible to write your own pre-emptive threading library. Roughly speaking, you have an alarm every 50ms or so, and switch to the next waiting thread. So in this sense, the answer is yes – you start by writing a pre-emptive threading library for the single-threaded platform, then you port your application quite easily.

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật