In C, I have several threads producing long values, and one thread consuming them. Therefore, I need a fixed-size buffer implemented similarly to Wikipedia and methods that access it in a thread-safe manner.
At a general level, the following should be done:
- When added to a full buffer, the stream should be blocked (without overwriting old values).
- The consumer stream should be blocked until the buffer is full - its work will have a high constant cost and should do as much work as possible. (Does this call with two buffers?)
I would like to use a proven implementation, preferably from a library. Any ideas?
Motivation and explanation:
I am writing JNI code related to removing global links stored as tags in heap objects.
When the ObjectFree JVMTI event ObjectFree , I get a long tag representing a global link that I need to free using DeleteGlobalRef . For this I need a JNIEnv link - and getting it is really expensive, so I want to buffer requests and delete as many as possible at the same time.
There may be many threads receiving an ObjectFree event, and there will be one thread (mine) doing the removal of the link.
source share