[Ace-users] [ace-users] Problem with ACE_Thread_Semaphore

Douglas C. Schmidt schmidt at dre.vanderbilt.edu
Tue Dec 18 11:03:20 CST 2007


Hi Jonas,

>     ACE VERSION: 5.6.1

Thanks for using the PRF.

>     HOST MACHINE and OPERATING SYSTEM:
> P4 with Fedora Core 7
> 
>     TARGET MACHINE and OPERATING SYSTEM, if different from HOST:
>     COMPILER NAME AND VERSION (AND PATCHLEVEL):
> 
>     THE $ACE_ROOT/ace/config.h FILE [if you use a link to a platform-
>     specific file, simply state which one]:
> Using rpm for FC7 downloaded from http://dist.bonsai.com/ken/ace_tao_rpm/index.html
> 
>     THE $ACE_ROOT/include/makeinclude/platform_macros.GNU FILE [if you
>     use a link to a platform-specific file, simply state which one
>     (unless this isn't used in this case, e.g., with Microsoft Visual
>     C++)]:
> 
>     CONTENTS OF $ACE_ROOT/bin/MakeProjectCreator/config/default.features
>     (used by MPC when you generate your own makefiles):
> 
>     AREA/CLASS/EXAMPLE AFFECTED:
> [What example failed?  What module failed to compile?]
> 
>     DOES THE PROBLEM AFFECT:
>         COMPILATION? No
>         LINKING? No
>         EXECUTION? Yes
> 
>     SYNOPSIS:
> Problem sync threads with ACE_Thread_Semaphore
> 
>     DESCRIPTION:
> A simple testprogram (see below) fails to sync two thread using ACE_Thread_Semaphore. The program creates a
> ACE_Thread_Semaphore which initially is locked. The main-thread creates a new thread and when waits for this thread by
> calling acquire() on the semaphore. The newly created thread starts by sleeping for a while and then calls release() on the
> semaphore.
> 
> When the main-thread reaches the semSync.acquire() is blocks as expected. Later when the new thread continue after initial
> sleep is calls semSync.release() is also blocks. This is not expected. Both threads blocks and the program hangs...

I tweaked your test a bit to print out when the main thread exits.  I
then tried running your test on Linux with 5.6.2.  Here's the output I
got:

% ./Semaphore_Test
main() - about to create thread...
main() - waiting for thread to start loop...
runThread() sleeping...
runThread() about to release...
runThread() sleeping...
main() - waiting for thread to stop...
runThread() sleeping...
runThread() sleeping...
runThread() sleeping...
runThread() sleeping...
main() - shutting down...
%

This appears to run fine.  Perhaps there's something odd with the
underlying OS semaphore implementation on Fedora Core 7?

Thanks,

        Doug

>     REPEAT BY:
> #include "ace/OS_NS_unistd.h"
> #include "ace/Thread.h"
> #include <ace/Thread_Semaphore.h>
> 
> #include <iostream>
> 
> ACE_Thread_Semaphore semSync(0);
> 
> ACE_THR_FUNC_RETURN runThread(void* /*param*/)
> {
>    std::wcout << "runThread() sleeping..." << std::endl;
>   
>    ACE_OS::sleep(5);
> 
>    std::wcout << "runThread() about to release..." << std::endl;
>    semSync.release();
>   
>    for(int i=0; i<5; ++i)
>    {
>       std::wcout << "runThread() sleeping..." << std::endl;
>       ACE_OS::sleep(1);
>    }
> 
>    semSync.release ();
> }
> 
> int main(int, char**)
> {
>    std::wcout << "main() - about to create thread..." << std::endl;
>    ACE_Thread::spawn(runThread);
>   
>    std::wcout << "main() - waiting for thread to start loop..." << std::endl;
>    semSync.acquire();
>   
>    std::wcout << "main() - waiting for thread to stop..." << std::endl;
> 
>    semSync.acquire();
>   
>    return 0;
> }
> 
> _______________________________________________
> ace-users mailing list
> ace-users at mail.cse.wustl.edu
> http://mail.cse.wustl.edu/mailman/listinfo/ace-users



More information about the Ace-users mailing list