Re: POSIX semaphores in JNI?

From: Stefan Poehn (stefan.poehn_at_IH8SPAMbms.de)
Date: 07/26/04


Date: Mon, 26 Jul 2004 12:34:36 +0200


"Kevin McMurtrie" <mcmurtri@dslextreme.com> schrieb im Newsbeitrag
news:mcmurtri-6D6280.00275024072004@corp-radius.supernews.com...
> Can POSIX semaphores be used in Java 1.4.2 JNI code? I have a C++ image
> rendering library that is I/O, memory, and CPU intensive. The
> operations can be lengthy and various stages of rendering are cached.
>

I have used Win32 and vxWorks Semaphores in a JNI project (2 years ago) and
both worked fine. Are the vxWorks semaphores posix compliant?

If you call a method that blocks on a taken semaphore, it does not matter if
you call from C/C++ or Java, all methods will block.

The only pitfall I have encountered is: You cannot create a thread in C/C++
and send any calls to the java virtual machine before you call
AttachCurrentThread.

> The thread management is fairly complex and fined-grained to make sure
> that operations do not interfere with each other, especially during I/O.
> Is it OK to use POSIX recursive semaphores to control threading? The
> JNI docs don't mention it. Information on the web conflicts or is
> obsolete (mentions green threads problem).
>
> MacOS X uses 1:1 pthreads. For Linux and Solaris, I'm not sure if the
> POSIX routines are safe. JNI threading could replace POSIX threading
> but I'm worried about its performance with large caches and numbers of
> semaphores. Also, maintaining proper references to the Java sync
> objects will be non-trivial. This library has an eventual memory
> corruption problem on Solaris only. I don't know if I should spend two
> days rewriting my semaphore C++ class for JNI threading or keep looking
> for the usual C++ memory bugs. The crash takes 6 to 12 hours to appear
> so debugging is time consuming.
>
>
> Thanks



Relevant Pages

  • POSIX semaphores in JNI?
    ... Can POSIX semaphores be used in Java 1.4.2 JNI code? ... Is it OK to use POSIX recursive semaphores to control threading? ...
    (comp.lang.java.programmer)
  • Re: Thread Locking issue - Cant allocate lock (sem_init fail)
    ... Each domain class also has its own lock, ... find any information about limits to the number of locks you can have ... I don't work with threading code but I have been working with semaphores for my IPC extensions. ... then I'd guess you're trying to create an awful lot of semaphores and that you're hitting some internal limit. ...
    (comp.lang.python)
  • Re: pragma importing sem_init gives me a segmentation fault
    ... POSIX semaphores by pragma importing sem_init, sem_post, sem_wait, ... previous semaphore calls were SGI specific and we were looking to move ... There is a package available for GNAT called florist. ...
    (comp.lang.ada)
  • Re: CreateThread Fails with ERROR_NOT_ENOUGH_MEMORY....
    ... We were able to figure out the stack of the culprit func. ... We have dispatched the bug to the relevant group owning the routine which was leaking semaphores & events & they are looking into it now. ... As far as the VM usage is concerned, I still believe that, given the amount of stress involved in the test, we are bound to run out of virtual memory. ... Now about the memory leak. ...
    (microsoft.public.win32.programmer.kernel)
  • Complete list of process attributes?
    ... memory, shared segments ... memory, shared segments (SysV) ... memory, data segment, arguments ... semaphores, memory ...
    (comp.unix.programmer)