How to minimize the time difference between two threads performing timestamp writes?

38 views
Skip to first unread message

r r

unread,
Nov 4, 2026, 1:51:28 PM (6 days ago) Nov 4
to mechanical-sympathy

I have two threads, each performing its own operations. My goal is to make the timestamps recorded by both threads as close to each other as possible.

long[] ts; // array of atomic longs 

Thread T1: 
 doWork1(); 
 ts[0] = get_monotonic_ts(); 

Thread T2:
 doWork2(); 
 ts[1] = get_monotonic_ts();

The objective is to minimize:

Math.abs(ts[1] - ts[0])

Ideally, the difference should be as close to zero as possible.

What would be the best way to implement this in Java?

Faraz Babar

unread,
Nov 4, 2026, 3:02:11 PM (6 days ago) Nov 4
to mechanica...@googlegroups.com
Maybe some context is missing? There are way too many variables at play, the content of work 1 and 2 are not known, most likely not atomic either, without which, either of them can get preempted unless thread pinning is in play. Apologies if I misunderstood your question but given the context, it is not possible to give a meaningful answer.

--
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 it, send an email to mechanical-symp...@googlegroups.com.
To view this discussion, visit https://groups.google.com/d/msgid/mechanical-sympathy/230fe176-f951-4b8c-a9fb-d38108e869c3n%40googlegroups.com.
Reply all
Reply to author
Forward
0 new messages