-2

After reading through this I now understand how to synchronize thread's critical sections on the native side of the JNI.

However, I cannot find equivalent functions for these 2 pthread calls: pthread_cond_timedwait() and pthread_cond_broadcast()

I have a long-running response-handler thread that is started in Java and then drops down into C to receive network data and then enqueue the data to a global shared response queue.

Concurrently I have multiple request threads that are started in Java and then drop down into C that issue network requests to a server and then wait for a response to show up on the global shared response queue.

The pertinent code in the long-running response thread is:

/* after enqueuing a network response to the global shared Q */
/* wake up all of the request threads waiting for a response */
pthread_cond_broadcast(&q_entry_cv);

And the pertinent code in the request threads:

if(q_entries == 0)
  pthread_cond_timedwait(&q_entry_cv, &qlock, &ts);
 /* wake up when the response thread has q'd a new response & search the q*/

Are there any equivalent JNI calls for these POSIX calls?

high5
  • 1
  • 2
  • There aren't any. What made you think there would be? – user207421 Mar 26 '21 at 09:28
  • The fact that the partial solution that is currently implemented is inadequate. – high5 Mar 26 '21 at 14:58
  • Maybe there is a viable alternative that someone other than user207421 and me can think of. – high5 Mar 26 '21 at 15:22
  • It's not a question of what anybody can think of. Your question is specifically about functions in the JNI environment, and they are all listed in the JNI Specification, and there aren't any for this purpose. I agree with @user0 that you should use `Object.wait()` and `Object.notifyAll()`, but you didn't ask about methods in the Java space. – user207421 Mar 27 '21 at 07:27

1 Answers1

1

It seems like you are talking about wait(long,int) and notifyAll() methods.
Every object in Java has these methods.
How to call an instance method from JNI is described here.

user0
  • 11
  • 1