This is the mail archive of the cygwin mailing list for the Cygwin project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

FW: 1.5.10: msgsnd between threads hangs, between processes ok..


Hi All,

I thought I would try one more time for any ideas... One more data point
is that same code compiles and runs on Redhat 7.3 and SUSE 9.1... Does
anyone else use IPC to communicate between threads successfully?

Thanks,

-Don

-----Original Message-----
From: Don Post 
Sent: Monday, August 23, 2004 2:24 PM
To: 'cygwin@cygwin.com'
Subject: 1.5.10: msgsnd between threads hangs, between processes ok..


Hi All,

I have encountered a problem which I hope someone has seen and has a
work around for. While I was porting some code that is based on POSIX
threads and SYSV message queues I found that if the receiver (i.e.
caller to msgrcv) of the message queue is a child or sibling thread of
the sender (i.e. caller to msgsnd), then the msgsnd call hangs
indefinitely even though NOWAIT is specified. If the receiver (caller to
msgrcv) is another process, then all works fine. I have included a
simple program that spawns the receiver either as a process (i.e. fork)
or as a thread (pthread_create). When fork is used, all works find. When
pthread_create is used, the send hangs. Any ideas/workarounds? I have
included  the appropriate versions and I have verified that the
cygserver is running. Also after the code I have included the output
from cygcheck -s....

Thanks,

-Don

#include <stdio.h>
#include <stdint.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <errno.h>
#include <stdlib.h>
#include <stdarg.h>
#include <unistd.h>
#include <string.h>
#include <sys/socket.h>
#include <sys/un.h>
#include <sys/msg.h>

static uint16_t   msgQueueMasterKey = 0xAC00;

typedef enum
{
    CHILD_THREAD  = 1,
    CHILD_PROCESS = 2
} client_mode_t;

void * doReceiveSide (void *argPtr)
{
    int    msgQueueId;
    char   msgBuffer[256];
    int    msgCount;

    msgCount = 0;
    printf ("Receiver Running...\n");

    msgQueueId = msgget(msgQueueMasterKey, IPC_CREAT|0660);

    while (1)
    {
        msgCount++;
        if (msgrcv (msgQueueId, msgBuffer, sizeof(msgBuffer), 0, 0) >=
0)
        {
            printf ("Message %d received: %s\n",msgCount, msgBuffer);
        }
        else 
        {
            printf ("Message not received: Error status returned.\n");
        }
    }

    return NULL;
}

int main(int argc, char *argv[])

{
    pthread_t        threadId;
    int              msgQueueId;
    char           * msgPtr = "This is the message.";
    client_mode_t    clientMode;

    if (argc != 2)
    {
        printf ("%s: usage %s <-fork | -thread>\n", argv[0], argv[0]);
        return 0;
    }
    else
    {
        if (strcmp (argv[1], "-fork") == 0)
            clientMode = CHILD_PROCESS;
        else if (strcmp (argv[1], "-thread") == 0)
            clientMode = CHILD_THREAD;
        else
        {
            printf ("%s: usage %s <-fork | -thread>\n", argv[0]);
            return 0;
        }
    }

    printf ("Starting client thread...\n");
    if (clientMode == CHILD_PROCESS)
    {
        if (fork() == 0) doReceiveSide(NULL);
    }
    else if (clientMode == CHILD_THREAD)
    {
        pthread_create(&threadId, NULL, doReceiveSide, (void
*)msgQueueId);
    }

    msgQueueId = msgget(msgQueueMasterKey, IPC_CREAT|0660);
    
    while (1)
    {
        printf ("Waiting 5 seconds...\n");
        fflush(stdout);
        sleep(5);

        printf ("Sending message on queue %d...\n",msgQueueId);
        fflush(stdout);

        msgsnd (msgQueueId, msgPtr, strlen(msgPtr), IPC_NOWAIT);

    }

}

---------------------------------------------

cygcheck -s 


Cygwin Configuration Diagnostics
Current System Time: Mon Aug 23 14:01:55 2004

Windows XP Professional Ver 5.1 Build 2600 Service Pack 1

Path: C:\cygwin\usr\local\bin
 C:\cygwin\bin
 C:\cygwin\bin
 C:\cygwin\usr\X11R6\bin
 c:\WINDOWS\system32
 c:\WINDOWS
 c:\WINDOWS\System32\Wbem
 c:\PROGRA~1\COMMON~1\Odbc\FILEMA~1
 c:\Program Files\ATI Technologies\ATI Control Panel
 c:\Program Files\Rational\common
 c:\Program Files\Rational\ClearCase\bin
 "C
 C:\cygwin\Program Files\Symantec\Norton Ghost 2003\"  c:\Program
Files\Microsoft SDK\Bin\  c:\Program Files\Microsoft SDK\Bin\WinNT\
c:\Program Files\vslick\win  c:\Program Files\Microsoft SDK\Bin\
c:\Program Files\Microsoft SDK\Bin\WinNT\
c:\PROGRA~1\MICROS~2\Common\msdev98\BIN
 c:\PROGRA~1\MICROS~2\VC98\BIN  c:\PROGRA~1\MICROS~2\Common\TOOLS\WINNT
 c:\PROGRA~1\MICROS~2\Common\TOOLS\
 C:\cygwin\bin
c:\home\dpost\ccviews\dpost_vxworks\vxworks_vob\vxworks21\Tornado\host\x
86-win32\bin

Output from C:\cygwin\bin\id.exe (nontsec)
UID: 1003(dpost) GID: 513(None)
513(None)

Output from C:\cygwin\bin\id.exe (ntsec)
UID: 1003(dpost) GID: 513(None)
544(Administrators)  545(Users)

SysDir: C:\WINDOWS\System32
WinDir: C:\WINDOWS

CYGWIN = `server'
HOME = `c:\home\dpost'
MAKE_MODE = `unix'
PWD = `/lib'
USER = `dpost'

Use `-r' to scan registry

c:  hd  NTFS   30004Mb  60% CP CS UN PA FC     
d:  cd           N/A    N/A                    
l:  hd  Ext2   44076Mb  50% CP CS              /
x:  net NTFS   134676Mb  46% CP CS    PA        dpost
z:  net          N/A    N/A                    

C:\cygwin      /          system  binmode
c:             /c         system  binmode
c:\home        /home      system  binmode
C:\cygwin/bin  /usr/bin   system  binmode
C:\cygwin/lib  /usr/lib   system  binmode
.              /cygdrive  system  binmode,cygdrive

Found: C:\cygwin\bin\awk.exe
Found: C:\cygwin\bin\bash.exe
Found: C:\cygwin\bin\cat.exe
Found:
c:\home\dpost\ccviews\dpost_vxworks\vxworks_vob\vxworks21\Tornado\host\x
86-win32\bin\cat.exe
Found: C:\cygwin\bin\cp.exe
Found: C:\cygwin\bin\cpp.exe
Found: C:\cygwin\bin\find.exe
Found: C:\cygwin\bin\gcc.exe
Found: C:\cygwin\bin\gdb.exe
Found: c:\Program Files\vslick\win\gdb.exe
Found: C:\cygwin\bin\grep.exe
Found: c:\Program Files\vslick\win\grep.exe
Found: C:\cygwin\bin\ld.exe
Found: C:\cygwin\bin\ls.exe
Found: C:\cygwin\bin\make.exe
Found:
c:\home\dpost\ccviews\dpost_vxworks\vxworks_vob\vxworks21\Tornado\host\x
86-win32\bin\make.exe
Found: C:\cygwin\bin\mv.exe
Found: C:\cygwin\bin\rm.exe
Found:
c:\home\dpost\ccviews\dpost_vxworks\vxworks_vob\vxworks21\Tornado\host\x
86-win32\bin\rm.exe
Found: C:\cygwin\bin\sed.exe
Found:
c:\home\dpost\ccviews\dpost_vxworks\vxworks_vob\vxworks21\Tornado\host\x
86-win32\bin\sed.exe
Found: C:\cygwin\bin\sh.exe
Found: C:\cygwin\bin\tar.exe

   61k 2003/08/09 C:\cygwin\bin\cygbz2-1.dll
   18k 2004/07/06 C:\cygwin\bin\cygcharset-1.dll
    7k 2003/10/19 C:\cygwin\bin\cygcrypt-0.dll
  841k 2004/03/17 C:\cygwin\bin\cygcrypto-0.9.7.dll
  617k 2004/03/22 C:\cygwin\bin\cygcurl-2.dll
   22k 2004/02/10 C:\cygwin\bin\cygcygipc-2.dll
  380k 2002/07/24 C:\cygwin\bin\cygdb-3.1.dll
  895k 2004/04/28 C:\cygwin\bin\cygdb-4.2.dll
  487k 2002/07/24 C:\cygwin\bin\cygdb_cxx-3.1.dll
 1156k 2004/04/28 C:\cygwin\bin\cygdb_cxx-4.2.dll
  155k 2004/01/07 C:\cygwin\bin\cygexpat-0.dll
   71k 2004/08/04 C:\cygwin\bin\cygexslt-0.dll
   45k 2001/04/25 C:\cygwin\bin\cygform5.dll
   35k 2002/01/09 C:\cygwin\bin\cygform6.dll
   48k 2003/08/09 C:\cygwin\bin\cygform7.dll
   28k 2003/07/20 C:\cygwin\bin\cyggdbm-3.dll
   30k 2003/08/11 C:\cygwin\bin\cyggdbm-4.dll
   19k 2003/03/22 C:\cygwin\bin\cyggdbm.dll
   15k 2003/07/20 C:\cygwin\bin\cyggdbm_compat-3.dll
   15k 2003/08/11 C:\cygwin\bin\cyggdbm_compat-4.dll
  107k 2004/07/06 C:\cygwin\bin\cyggettextlib-0-14-1.dll
   17k 2004/07/06 C:\cygwin\bin\cyggettextpo-0.dll
  190k 2004/07/06 C:\cygwin\bin\cyggettextsrc-0-14-1.dll
  489k 2003/08/09 C:\cygwin\bin\cygguile-12.dll
  489k 2003/07/28 C:\cygwin\bin\cygguile-12abi13.dll
   24k 2003/08/09 C:\cygwin\bin\cygguile-ltdl-1.dll
   24k 2003/07/28 C:\cygwin\bin\cygguile-ltdl-1abi13.dll
   62k 2003/08/09 C:\cygwin\bin\cygguile-srfi-srfi-13-14-v-1-1.dll
   62k 2003/07/28 C:\cygwin\bin\cygguile-srfi-srfi-13-14-v-1-1abi13.dll
   23k 2003/08/09 C:\cygwin\bin\cygguile-srfi-srfi-4-v-1-1.dll
   23k 2003/07/28 C:\cygwin\bin\cygguile-srfi-srfi-4-v-1-1abi13.dll
   11k 2003/08/09 C:\cygwin\bin\cygguilereadline-v-12-12.dll
   11k 2003/07/28 C:\cygwin\bin\cygguilereadline-v-12-12abi13.dll
   17k 2001/06/28 C:\cygwin\bin\cyghistory4.dll
   29k 2003/08/10 C:\cygwin\bin\cyghistory5.dll
  330k 2004/02/09 C:\cygwin\bin\cyghttpd.dll
  991k 2004/07/06 C:\cygwin\bin\cygiconv-2.dll
   22k 2001/12/13 C:\cygwin\bin\cygintl-1.dll
   37k 2003/08/10 C:\cygwin\bin\cygintl-2.dll
   54k 2004/07/06 C:\cygwin\bin\cygintl-3.dll
   12k 2003/02/17 C:\cygwin\bin\cygioperm-0.dll
  119k 2002/02/09 C:\cygwin\bin\cygjpeg6b.dll
   60k 2003/09/17 C:\cygwin\bin\cygkpathsea-3.dll
   60k 2003/07/27 C:\cygwin\bin\cygkpathsea-3abi13.dll
   40k 2004/07/07 C:\cygwin\bin\cygltdl-3.dll
   26k 2001/04/25 C:\cygwin\bin\cygmenu5.dll
   20k 2002/01/09 C:\cygwin\bin\cygmenu6.dll
   29k 2003/08/09 C:\cygwin\bin\cygmenu7.dll
   15k 2003/11/20 C:\cygwin\bin\cygminires.dll
  404k 2004/03/26 C:\cygwin\bin\cygnaim_core-0.dll
  156k 2001/04/25 C:\cygwin\bin\cygncurses++5.dll
  175k 2002/01/09 C:\cygwin\bin\cygncurses++6.dll
  226k 2001/04/25 C:\cygwin\bin\cygncurses5.dll
  202k 2002/01/09 C:\cygwin\bin\cygncurses6.dll
  224k 2003/08/09 C:\cygwin\bin\cygncurses7.dll
   15k 2001/04/25 C:\cygwin\bin\cygpanel5.dll
   12k 2002/01/09 C:\cygwin\bin\cygpanel6.dll
   19k 2003/08/09 C:\cygwin\bin\cygpanel7.dll
   62k 2003/12/11 C:\cygwin\bin\cygpcre-0.dll
   63k 2003/04/11 C:\cygwin\bin\cygpcre.dll
    9k 2003/12/11 C:\cygwin\bin\cygpcreposix-0.dll
   61k 2003/04/11 C:\cygwin\bin\cygpcreposix.dll
 1061k 2004/08/19 C:\cygwin\bin\cygperl5_8_5.dll
  168k 2003/08/10 C:\cygwin\bin\cygpng10.dll
  173k 2003/08/10 C:\cygwin\bin\cygpng12.dll
   22k 2002/06/09 C:\cygwin\bin\cygpopt-0.dll
  108k 2001/06/28 C:\cygwin\bin\cygreadline4.dll
  148k 2003/08/10 C:\cygwin\bin\cygreadline5.dll
  672k 2003/12/25 C:\cygwin\bin\cygruby18.dll
  171k 2004/03/17 C:\cygwin\bin\cygssl-0.9.7.dll
  254k 2003/09/18 C:\cygwin\bin\cygtidy-0-99-0.dll
  281k 2003/02/24 C:\cygwin\bin\cygtiff3.dll
 1226k 2004/08/04 C:\cygwin\bin\cygxml2-2.dll
  200k 2004/08/04 C:\cygwin\bin\cygxslt-1.dll
   61k 2003/12/04 C:\cygwin\bin\cygz.dll
 1126k 2004/05/26 C:\cygwin\bin\cygwin1.dll
    Cygwin DLL version info:
        DLL version: 1.5.10
        DLL epoch: 19
        DLL bad signal mask: 19005
        DLL old termios: 5
        DLL malloc env: 28
        API major: 0
        API minor: 116
        Shared data: 4
        DLL identifier: cygwin1
        Mount registry: 2
        Cygnus registry name: Cygnus Solutions
        Cygwin registry name: Cygwin
        Program options name: Program Options
        Cygwin mount registry name: mounts v2
        Cygdrive flags: cygdrive flags
        Cygdrive prefix: cygdrive prefix
        Cygdrive default prefix: 
        Build date: Tue May 25 22:07:00 EDT 2004
        CVS tag: cr-0x5e6
        Shared id: cygwin1S4

  386k 2003/10/22
c:\home\dpost\ccviews\dpost_vxworks\vxworks_vob\vxworks21\Tornado\host\x
86-win32\bin\cygwinb19.dll

Cygwin Package Information
Package              Version            
_update-info-dir     00227-1            
apache               1.3.29-2           
ash                  20040127-1         
astyle               1.15.3-3           
autoconf             2.59-1             
autoconf-devel       2.59-1             
autoconf-stable      2.13-5             
automake             1.7.9-1            
automake-devel       1.8.5-1            
automake-stable      1.4p6-2            
base-files           3.0-2              
base-passwd          1.1-1              
bash                 2.05b-16           
binutils             20040725-2         
bzip2                1.0.2-5            
c-client             2002e-3            
ccache               2.2-1              
ccdoc                0.8.39-1           
check                0.8.4-1            
cmake                2.0.3-1            
compface             1.4-5              
crypt                1.1-1              
ctags                5.5-4              
curl                 7.11.1-1           
curl-devel           7.11.1-1           
cvs                  1.11.6-3           
cygipc               2.03-2             
cygrunsrv            1.0-1              
cygutils             1.2.5-1            
cygwin               1.5.10-3           
cygwin-doc           1.3-7              
d                    1.2.0-1            
dejagnu              20021217-2         
diffutils            2.8.7-1            
doxygen              1.2.18-1           
dpkg                 1.10.4-2           
editrights           1.01-1             
expat                1.95.7-1           
expect               20030128-1         
file                 4.09-1             
fileutils            4.1-2              
findutils            4.1.7-4            
flex                 2.5.4a-3           
gawk                 3.1.4-3            
gcc                  3.3.3-2            
gcc-core             3.3.3-3            
gcc-g++              3.3.3-3            
gcc-mingw            20040810-1         
gcc-mingw-core       20040810-1         
gcc-mingw-g++        20040810-1         
gcc2                 2.95.3-10          
gdb                  20030919-1         
gdbm                 1.8.3-7            
gettext              0.14.1-1           
gettext-devel        0.14.1-1           
gperf                2.7.2-1            
grep                 2.5-1              
groff                1.18.1-2           
guile                1.6.4-12           
guile-devel          1.6.4-12           
gzip                 1.3.5-1            
indent               2.2.9-1            
ioperm               0.4-1              
less                 381-1              
libbz2_1             1.0.2-5            
libcharset1          1.9.2-1            
libdb3.1             3.1.17-2           
libdb4.2             4.2.52-1           
libgdbm              1.8.0-5            
libgdbm-devel        1.8.3-7            
libgdbm3             1.8.3-3            
libgdbm4             1.8.3-7            
libgettextpo0        0.14.1-1           
libguile12           1.6.4-12           
libguile12abi13      1.6.4-2            
libiconv             1.9.2-1            
libiconv2            1.9.2-1            
libintl1             0.10.40-1          
libintl2             0.12.1-3           
libintl3             0.14.1-1           
libjpeg6b            6b-8               
libkpathsea3         2.0.2-13           
libkpathsea3abi13    2.0.2-2            
libltdl3             1.5.6-3            
libncurses-devel     5.3-4              
libncurses5          5.2-1              
libncurses6          5.2-8              
libncurses7          5.3-4              
libpcre              4.1-1              
libpcre0             4.5-1              
libpng10             1.0.15-4           
libpng12             1.2.5-4            
libpopt0             1.6.4-4            
libreadline4         4.1-2              
libreadline5         4.3-5              
libtiff3             3.6.0-2            
libtool              1.5b-1             
libtool-devel        1.5.6-3            
libtool-stable       1.4.3-2            
libxml2              2.6.11-1           
libxslt              1.1.8-1            
login                1.9-7              
m4                   1.4-1              
make                 3.80-1             
man                  1.5k-3             
mc                   4.6.0-4            
mingw-runtime        3.3-1              
minires              0.97-1             
mktemp               1.5-3              
more                 2.11o-1            
naim                 0.11.6.7-1         
nasm                 0.98.38-1          
ncftp                3.1.7-1            
ncurses              5.3-4              
openssh              3.9p1-1            
openssl              0.9.7d-1           
openssl-devel        0.9.7d-1           
patch                2.5.8-8            
patchutils           0.2.30pre1-1       
pcre                 4.5-1              
pcre-devel           4.5-1              
pcre-doc             4.5-1              
perl                 5.8.5-3            
pkgconfig            0.15.0-4           
procps               010801-2           
rcs                  5.7-3              
readline             4.3-5              
rsync                2.6.2-2            
ruby                 1.8.1-1            
sed                  4.0.9-2            
sh-utils             2.0.15-4           
sharutils            4.2.1-3            
splint               3.1.1-1            
swig                 1.3.19-1           
tar                  1.13.25-5          
tcltk                20030901-1         
tcsh                 6.13.00-2          
termcap              20021106-2         
terminfo             5.3_20030726-1     
tetex-devel          2.0.2-13           
texinfo              4.2-4              
textutils            2.0.21-1           
tidy                 030901-1           
units                1.77-1             
unzip                5.50-5             
uw-imap              2002e-3            
vim                  6.3-1              
w32api               2.5-1              
wget                 1.9.1-1            
which                1.5-2              
xerces-c-devel       2.5.0-1            
zip                  2.3-6              
zlib                 1.2.1-1            
Use -h to see help about each section

--
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple
Problem reports:       http://cygwin.com/problems.html
Documentation:         http://cygwin.com/docs.html
FAQ:                   http://cygwin.com/faq/


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]