Re: Compute in a lock free way

2022-06-04 Thread Dain Ironfoot
Thanks so much Remi! Really like how you separated the computation and the thread-safety part. Wish I had thought of that :) -- You received this message because you are subscribed to the Google Groups "mechanical-sympathy" group. To unsubscribe from this group and stop receiving emails from

Re: Compute in a lock free way

2022-06-04 Thread Remi Forax
> From: "Dain Ironfoot" > To: "mechanical-sympathy" > Sent: Saturday, June 4, 2022 5:11:49 PM > Subject: Re: Compute in a lock free way > Thank you so much Remi!! > I took your advice of using CAS to update both of them and came up with this > (Can't use record as still on JDK 11). > Does this

Re: Compute in a lock free way

2022-06-04 Thread Dain Ironfoot
Thanks Heinz! Please correct me if I am wrong but your approach, on a high level, sounds similar to Remi's approach? In Remi's approach, we are CASing and atomically updating the state ourselves. However, in your approach, we would delegate it to LongAccumulator? On Saturday, June 4, 2022 at

Re: Compute in a lock free way

2022-06-04 Thread Dain Ironfoot
Thank you so much Remi!! I took your advice of using CAS to update both of them and came up with this (Can't use record as still on JDK 11). Does this look ok? public final class Computer { public static class Stat{ private final BigDecimal sum; private final int count; public

Re: Compute in a lock free way

2022-06-04 Thread Dain Ironfoot
Thank you so much!! I took your advice of using CAS to update both of them and came up with this (Can't use record as still on JDK 11). Does this look ok? public final class Computer { public static class Stat{ private final BigDecimal sum; private final int count; public

Re: Compute in a lock free way

2022-06-04 Thread John
Hello anonymous internet user :) I cant understand the full context of the problem and am curious about it. I don't understand how aggregating prices into a mean value but can be used to produce a meaningful signal. So some questions: Do you reset the average periodically? Do you take

Re: Compute in a lock free way

2022-06-04 Thread Dr Heinz M. Kabutz
What is the maximum count and sum? Could the two fit into a 64 bit long? If so a LongAccumulator could be made to work. On Sat, 04 Jun 2022 at 01:53, Dain Ironfoot wrote: > Hello, > > I am writing a class to calculate average of prices. We use it to generate > buy/sell signal for some financial

Re: Compute in a lock free way

2022-06-04 Thread Remi Forax
- Original Message - > From: "Laurynas Biveinis" > To: "mechanical-sympathy" > Sent: Saturday, June 4, 2022 11:03:28 AM > Subject: Re: Compute in a lock free way >> I am writing a class to calculate average of prices. We use it to generate >> buy/sell signal for some financial

Re: Compute in a lock free way

2022-06-04 Thread Laurynas Biveinis
> I am writing a class to calculate average of prices. We use it to generate > buy/sell signal for some financial instruments therefore latency is crucial. > Prices are sent via different threads therefore class needs to be thread-safe. > > Am I correct in understanding that I have to use a

Re: Compute in a lock free way

2022-06-04 Thread Remi Forax
> From: "Dain Ironfoot" > To: "mechanical-sympathy" > Sent: Saturday, June 4, 2022 12:53:55 AM > Subject: Compute in a lock free way > Hello, > I am writing a class to calculate average of prices. We use it to generate > buy/sell signal for some financial instruments therefore latency is