Forums Register Login

Multiprocessor question

+Pie Number of slices to send: Send
Is there anything in particular to pay attention to code multithreaded Java apps in multiprocessor CPUs?
+Pie Number of slices to send: Send
You mean as opposed to multihtreaded code running on a single CPU?

No.

It doesn't matter what kind of hardware your code runs on. When writing multithreaded code, you always have to take the same steps to ensure proper handling of shared data. One CPU or a thousand, it makes no difference.
+Pie Number of slices to send: Send
 

Jeff Verdegan wrote:You mean as opposed to multihtreaded code running on a single CPU?

No.

It doesn't matter what kind of hardware your code runs on. When writing multithreaded code, you always have to take the same steps to ensure proper handling of shared data. One CPU or a thousand, it makes no difference.




Having worked with JVMs running on hundreds of cores, I have to recommend that there is a difference (regarding testing) -- and if you intend to run your application in production with hundreds of cores, make sure that your test environment also has hundreds of cores.

It is amazing how easy race conditions show up when there are hundreds of cores, and never do, when there are only a handful. And I don't just mean your application, I mean commercial products, open-sourced libraries, etc. We had to work around many bugs (along with reporting them) with various libraries (and application servers) that have been in heavy use (and trusted) for years.

Henry
1
+Pie Number of slices to send: Send
 

Henry Wong wrote:

Jeff Verdegan wrote:You mean as opposed to multihtreaded code running on a single CPU?

No.

It doesn't matter what kind of hardware your code runs on. When writing multithreaded code, you always have to take the same steps to ensure proper handling of shared data. One CPU or a thousand, it makes no difference.




Having worked with JVMs running on hundreds of cores, I have to recommend that there is a difference (regarding testing) -- and if you intend to run your application in production with hundreds of cores, make sure that your test environment also has hundreds of cores.

It is amazing how easy race conditions show up when there are hundreds of cores, and never do, when there are only a handful.



Absolutely true. And if you know how many cores you'll be running on, you can tailor your code to take optimal advantage of that.

My point was simply that the same race conditions that you'll more likely see on a hundred cores can happen on a single core, as far as the rules of the Java language and the JVM are concerned, so there's nothing additional that you have to take into account in order to write correct code.

+Pie Number of slices to send: Send
 

Jeff Verdegan wrote: so there's nothing additional that you have to take into account in order to write correct code.



OK, I'll grant that.

But I also maintain that "writing correct code" using Java is far harder than most folk think when they start reading about the subject.
IMHO, Java's tools are the minimum you need, if you are as good as someone like @Henry, to do the job. But they do not approach making it easy to do.

Since it is hard to write correct code, its easy to write incorrect code. Its a lot easier to trigger the bad code, bad race conditions, etc. when you have lots of cores. Deciding what number defines "lots of cores" is an exercise to the reader.

These days, 6 core X86 processors cost $100. For $200, its easy to get 6 core processors that use hyper-threading techniques to act like 12 cores. I fully expect 16 core systems to be cheap and in production before this coming Christmas.

1
+Pie Number of slices to send: Send
 

Pat Farrell wrote:
But I also maintain that "writing correct code" using Java is far harder than most folk think when they start reading about the subject.



No! The "21 days" book wouldn't lie to me!

But yeah, writing correct code is hard enough, but when you bring multithreading into the picture, it gets enormously more complex, and it's a lot harder to test.
Don't MAKE me come back there with this tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com


reply
reply
This thread has been viewed 772 times.
Similar Threads
Is Concurency dependent on CPU architecture?
Threading in Multiprocesser environment
Cause a thread to stop
Thread.currentthread method on multi cpu
SMT
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 28, 2024 22:46:32.