T.R | Title | User | Personal Name | Date | Lines |
---|
3315.1 | One mistake, plus bonus information | HYDRA::NEWMAN | Chuck Newman, 508/467-5499 (DTN 297), MRO1-3/F26 | Thu Mar 13 1997 10:41 | 9 |
| 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.2 | Chuck's advice mailed to customer... | RDGENG::READINGS_R | Richard Readings | Fri Mar 14 1997 06:54 | 16 |
| 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.3 | Reply from customer | RDGENG::ddors.reo.dec.com::readings_r | | Fri Mar 14 1997 08:58 | 143 |
| 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.4 | Blech! Following sent to developer | HYDRA::NEWMAN | Chuck Newman, 508/467-5499 (DTN 297), MRO1-3/F26 | Fri Mar 14 1997 11:40 | 124 |
| 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
}
}
}
}
}
}
|