[Search for users] [Overall Top Noters] [List of all Conferences] [Download this site]

Conference hydra::axp-developer

Title:Alpha Developer Support
Notice:[email protected], 800-332-4786
Moderator:HYDRA::SYSTEM
Created:Mon Jun 06 1994
Last Modified:Fri Jun 06 1997
Last Successful Update:Fri Jun 06 1997
Number of topics:3722
Total number of notes:11359

3315.0. "Dialogica - Point 22593" by KZIN::ASAP () Thu Mar 13 1997 02:48

    Company Name :  Dialogica - Point 22593
    Contact Name :  Simon Jackson
    Phone        :  44 1252 844000
    Fax          :  44 1252 844525
    Email        :  [email protected]
    Date/Time in :  13-MAR-1997 07:48:03
    Entered by   :  Richard Readings
    SPE center   :  REO

    Category     :  unix
    OS Version   :  4
    System H/W   :  


    Brief Description of Problem:
    -----------------------------

From:	ESSB::ESSB::MRGATE::"ILO::ESSC::snation" 12-MAR-1997 18:01:17.38
To:	RDGENG::ASAP
CC:	
Subj:	ESCALATION: POINT No 22593  Company Dialogic Telecom TO ASAP READING:  DCE porting problem

From:	NAME: ESCTECH@ILO          
	TEL: (822-)6704          
	ADDR: ILO                  <snation@ESSC@ILO>
To:	ASAP@RDGENG@MRGATE

Hello - 

POINT Log Number	22593 

Company Name 	Dialogica

Engineers name	  Simon Jackson

Telephone Number 	44 1252 844000	

Fax Number	44 1252 844525	

E-mail Address		[email protected]

Operating System, Version	Digital UNIX 4.0

Platform			

Problem Statement	

Hi,

    I am a member of the ASAP programmme (membership number A60467) and I 
have a query about a problem porting some DCE code from DEC OSF/1 to 
Digital Unix Version 4.



I am having trouble getting the code to compile in my environment. I am 
running Digital Unix V4 with the version 2 DCE application developers 
kit. Below are the subsets installe don my system.



DCEADK200            installed  DCE Application Developers Kit V2.0

DCEADKMAN200         installed  DCE Application Developers Manual Pages 
V2.0

DCERTS200            installed  DCE Runtime Services V2.0



I have written a simple short program which exhibits the same errors 
during compile.



The compile line is: 

      cc -threads test.c



The output I get is:



# cc -threads test.c

cc: Error: test.c, line 9: In this statement, "ptdexc_mutex_init(...)" 
has void

type, but occurs in a context that requires a non-void result.

if(pthread_mutex_init(&mymutex, pthread_mutexattr_default) != 0)

---^

cc: Error: test.c, line 13: In this statement, "ptdexc_mutex_lock(...)" 
has void

 type, but occurs in a context that requires a non-void result.

    if(pthread_mutex_lock(&mymutex) != 0)

-------^

cc: Error: test.c, line 17: In this statement, "ptdexc_mutex_lock(...)" 
has void

 type, but occurs in a context that requires a non-void result.

        if(pthread_mutex_lock(&mymutex) != 0)

-----------^



Here is the source of the program:



#include <dce/pthread_exc.h>

#include <stdio.h>

 

int main()

{

 

    pthread_mutex_t mymutex;

 

if(pthread_mutex_init(&mymutex, pthread_mutexattr_default) != 0)

    printf("Mutex create failed\n");

else

    {

    if(pthread_mutex_lock(&mymutex) != 0)

        printf("Mutex lock failed\n");

    else

        {

        if(pthread_mutex_lock(&mymutex) != 0)

            {

            printf("Mutex unlock failed\n");

            }

        }

    }

}

                                                       

Any ideas why this is not working??



Cheers Simon....                                                          
            

==========================

Regards,

Sean Nation



 Se�n Nation
 Technical Support                                    FAX:    DTN 822 4445  
 European Customer Service Centre                     Phone:  DTN 822 4355  
 Digital Equipment International B.V.      E-Mail: [email protected] 
                                                                            
           FREEPHONE numbers are available on request.                 


T.RTitleUserPersonal
Name
DateLines
3315.1One mistake, plus bonus informationHYDRA::NEWMANChuck Newman, 508/467-5499 (DTN 297), MRO1-3/F26Thu Mar 13 1997 10:419
Richard --

He's using the wrong include file.  He's specifying <dce/pthread_exc.h> but
he should specify <pthread.h> instead.

One other note:  on the compile he's using -threads, which references the
old draft standard for threads.  Encourage him to use -pthread.

								-- Chuck Newman
3315.2Chuck's advice mailed to customer...RDGENG::READINGS_RRichard ReadingsFri Mar 14 1997 06:5416
Simon,

You should replace

#include <dce/pthread_exc.h>

with

#include <pthread.h>

Also in your compile line 

      cc -threads test.c

you're referencing the old draft standard with -threads. We recommend
that you use -pthread instead.
3315.3Reply from customerRDGENG::ddors.reo.dec.com::readings_rFri Mar 14 1997 08:58143
The example I sent does indeed compile with the change in header file. 
The reason I used the other one is that our main code uses the RPC 
exception handling interface (TRY CATCH ENDTRY macros). The OSF books say 
the the pthread_exc interface should be used in this case. I modified the 
example I sent to use this and it still appears to work with the 
pthread.h header. Any reason why this does not follow the OSF convention? 
(See Section 9.2 in OSF DCE Application Development Core Components 
Release 1.1)

Interestingly if I try to use the -pthread in the example I get  errors 
out of compile:



#cc -pthread test.c

cc: Error: test.c, line 11: Missing ";".

    status = pthread_mutex_init(&mymutex, pthread_mutexattr_default);

----^

cc: Error: test.c, line 13: Missing ";".

   printf("Exception encountered\n");

---^

cc: Error: test.c, line 16: Missing ";".

if(status == 0)

^

cc: Error: test.c, line 19: Missing ";".

        status = pthread_mutex_lock(&mymutex);

--------^

cc: Error: test.c, line 21: Missing ";".

       printf("Exception encountered\n");

-------^

cc: Error: test.c, line 23: Missing ";".

    }

----^

cc: Error: test.c, line 28: Missing ";".

        status = pthread_mutex_unlock(&mymutex);

--------^

cc: Error: test.c, line 30: Missing ";".

       printf("Exception encountered\n");

-------^

cc: Error: test.c, line 32: Missing ";".

    }

----^                                                          

Modified code which give the above error.:



# cat test.c

#include <pthread.h>

#include <stdio.h>

 

int main()

{

 

    pthread_mutex_t mymutex;

    int status;

 

TRY

    status = pthread_mutex_init(&mymutex, pthread_mutexattr_default);

CATCH_ALL

   printf("Exception encountered\n");

ENDTRY

 

if(status == 0)

    {

    TRY

        status = pthread_mutex_lock(&mymutex);

    CATCH_ALL

       printf("Exception encountered\n");

    ENDTRY

    }

 

if(status == 0)

    {

    TRY

        status = pthread_mutex_unlock(&mymutex);

    CATCH_ALL

       printf("Exception encountered\n");

    ENDTRY

    }

}


3315.4Blech! Following sent to developerHYDRA::NEWMANChuck Newman, 508/467-5499 (DTN 297), MRO1-3/F26Fri Mar 14 1997 11:40124
The TRY/CATCH/CATCH_ALL/ENDTRY macros appear to be "namespace-polluting"

Here's an extract from pthread_exception.h

/*
 * This header file consists of two sections. The first is ANSI/POSIX
 * "clean", with no names disallowed by the standards (all names either begin
 * with "_" and a capital letter, or "__" and a lower case letter, or use the
 * POSIX 1003.1c-1995 "extension" namespace "PTHREAD" prefix with "_NP"
 * suffix or "pthread" prefix with "_np" suffix). The second contains the
 * "namespace-polluting" (non-standard) definitions that we've traditionally
 * documented for client use -- TRY, ENDTRY, and so forth. The two sections
 * each have separate "ifndef" tests, which allows this header file to be
 * included twice by the same module (once for the clean defintions and once
 * for the polluting definitions) and still have everything work out nicely.
 */


From my search of the header files it appears that there are two ways to 
use the TRY/CATCH/CATCH_ALL/ENDTRY construct:

1)  Use the PTHREAD_xxx_NP syntax instead
2)  Define the macro -D_PTHREAD_CORE_BUILD_.  This may well have other
	implications, so I'd recommend method 1.

The following sample works, generating an ACCVIO in the TRY block
You may compile with either method 1) or 2).

								-- Chuck Newman
--------------------------------------------------------------------------------
#ifdef _PTHREAD_CORE_BUILD_
#define Abc
#endif

#if 0
A.2.1 Including DECthreads Header Files

Include one of the DECthreads header files shown in Table A-1 in your program to
use the appropriate DECthreads library:

Table A-1 DECthreads Header Files



Header File           Interface

pthread.h             POSIX 1003.1c-1995 routines

tis.h                 tis routines (tis_)

cma.h                 cma routines (cma_)

pthread_d4.h          POSIX 1003.4a Draft 4 routines with status-
                      returning interface

pthread_exc.h         POSIX 1003.4a Draft 4 routines with exception-
                      returning interface


Do not include more than one of the above header files in your module.
#endif
#include <stdio.h>
#include <pthread.h>

int main()
{
volatile long stuff;
    pthread_mutex_t mymutex;
    pthread_mutexattr_t mymutexattr;

if (pthread_mutexattr_init(&mymutexattr) != 0)
    printf("Mutex attribute initialization failed\n");
else
    {
    if (pthread_mutexattr_settype_np(&mymutexattr, PTHREAD_MUTEX_RECURSIVE_NP) != 0)
        printf("Mutex attribute modification failed\n");
    else
        {
        if (pthread_mutex_init(&mymutex, &mymutexattr) != 0)
            printf("Mutex create failed\n");
        else
            {
            if (pthread_mutex_lock(&mymutex) != 0)
                printf("Mutex lock failed\n");
            else
                {
                if (pthread_mutex_lock(&mymutex) != 0)
                    {
                    printf("Mutex unlock failed\n");
                    }
                else
                    {
                    stuff = 42L;
#ifdef Abc
                    TRY {
                        stuff = (long)(&mymutex);
                        stuff = *(long *)stuff;
                        stuff = *(long *)stuff;
                        }
                    CATCH_ALL {
                        stuff = 0L;
                        printf("Mayday Mayday!!! We're goin' in!!!\n");
                        RERAISE;
                        }
                    ENDTRY
#else
                    PTHREAD_TRY_NP {
                        stuff = (long)(&mymutex);
                        stuff = *(long *)stuff;
                        stuff = *(long *)stuff;
                        }
                    PTHREAD_CATCH_ALL_NP {
                        stuff = 0L;
                        printf("Mayday Mayday!!! We're goin' in!!!\n");
                        PTHREAD_RERAISE_NP;
                        }
                    PTHREAD_ENDTRY_NP
#endif
                    }
                }
            }
        }
    }
}