Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

Or you just use static atomic variables no?

I mean it wont solve your race conditions but it also wont crash.

And it will be VERY fast because parallelism without cache misses!

I wish there was a Java with C struct JNI access.



Saying this as a big hardware atomics enjoyer: Static atomic variables are not fast, are not parallel and definitely are the worst kind of cache misses.

Atomics are also atomic only on that one single operation, such as manipulating a single number in a struct or swapping out a pointer from one version of an object to another. To atomically expose a set of changes to a datastructure, you either use a lock or swap the old for the new, which is the driving example in the article.


This is false. Depending on the CPU Arch, updating a shared static atomic variable may cause cache invalidation. How fast depends on how hot and tight you critical sections are.


Modern Java does support directly calling C functions, with structs. And also upcalls back to java. All without any JNI style preprocessing or stubs.

https://docs.oracle.com/en/java/javase/21/core/calling-c-lib...


Hm, ok I have Arrays of 64 byte atomic Structs defined in C and I want to iterate over them in Java, is that possible with the Memory API?


It's called C# (supporting plain C structs is just a small part of its low-level features)


Or D, available as official fronted language on GCC and LLVM projects, :)




Consider applying for YC's Winter 2027 batch! Applications are open till November 2.

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: