How are atomic operations are a dynamic language feature?

I was told that atomic operations are a dynamic language feature. I was too afraid to ask in that context what this actually means because I didn’t want my coworkers to think I’m stupid. But I actually don’t really understand this statement.

My understanding of the term “atomic operations” is any operation that is either wholly executed or wholly not executed; you will definitely never be halfway through the operation when the thread context switches.

What does this have to do with dynamic vs static typing?

10

I was too afraid to ask in that context what this actually means because I didn’t want my coworkers to think I’m stupid.

Actually, I think that asking questions is smart. It’s how you learn things that you don’t know. And in larger groups, it’s likely that other people don’t know it either, they’re just afraid to ask too.

My understanding of the term “atomic operations” is any operation that is either wholly executed or wholly not executed …

Yes, but that’s only part of it. Another important part is that the operation appears to execute instantaneously, that is, you can never observe it in half-completed state. (Though the following part of the sentence indicates that that’s what you meant.)

… such as in C# with the volatile keyword when setting or getting the value of a primitive, you will definitely never be halfway through getting or setting a volatile primitive when the thread context switches.

That’s not what volatile in C# is about. Setting the value of small primitive types (like int, char or reference, but not long or double) is always guaranteed to be atomic (see §5.5 Atomicity of variable references of the C# spec).

What volatile is about is the order of accessing the fields (§10.5.3 Volatile fields of the spec). Normally, if you write something like:

this.value = 42;
this.valueIsSet = true;

and then observe it from another thread, then you could see valueIsSet to be already true and value to be still 0, due to compiler and processor optimizations that reorder instructions. With volatile, such reordering is forbidden.

This also guarantees that the field is read every time, without volatile a loop like

while (this.shouldRun)
{
    // whatever; does not set this.shouldRun
}

might be compiled as:

if (this.shouldRun)
{
    while (true)
    {
        // whatever; does not set this.shouldRun
    }
}

In any case, using volatile correctly is hard and you should avoid it unless you really need it for performance reasons. Most of the time, using locks and thread-safe library types is enough.

What does this have to do with dynamic vs static typing?

No idea. There certainly are non-trivial atomic operations in .Net (like those in the Interlocked class).

The only thing I can think of is that some languages can use user-mode threads instead of native threads, and thus have more control over what operations are executed atomically, because it’s the language runtime that decides when to switch threads. But that has nothing to do with dynamic or static typing. (And I have no idea if there are languages that actually take advantage of that.)

2

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