[omniORB] Sun C++ 5 or 6 "throw" is not thread safe.

Arnault Bonafos arnault.bonafos@tumbleweed.com
Wed, 30 Aug 2000 14:12:45 -0700


--------------2FBD8B74343F5A3E887A090C
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit


After having compiled (with SunCompiler 5.0) the Sai Lai Lo revised program
from the omniORB archive on a Ultra 5 Solaris2.7
single processor machine (with all necessary patches), it appears that this
test works fine.
The test machine is a SMP machine Solaris2.7, 4 processors, with the OS
related patches applied.
Before applying the patches the program was not runnable because of some
linker issue.

Can Sai Lai Lo confirm, or someone else, that this test is supposed to fail
(crash) on a unpatched SMP machine, the message seems to be clear, I just want
to confirm this point.
Should the success of this test confirm the thread safety of SunCompiler 5.0?

The patches applied to the SMP machine are:
106327-08  SunOS 5.7: Shared library patch for C++
106748-04  SunOS 5.7: /usr/ccs/bin/sccs and /usr/ccs/bin/make patch

The first patch lists "4005413 throw is not thread safe" as being solved by
the patch, for reminder this is the bug
item that Sai Lai Lo pointed out in his message with the SMP test program.

I've used exactly the same program that is copied thereafter, the number of
threads was 5 50 and 200.

Sai-Lai Lo wrote:

> Unfortunately, things are not as simple as it first looks.
> I changed the test program to use pthread and corrected some obvious
> mistakes and it no longer SEGV.
>
> My omniorb test program still SEGV in exception unwinding though.
>
> Sai-Lai
>
> The revised test is as follows:
>
> #include <pthread.h>
> #include <stdio.h>
> #include <stdlib.h>
> #include <unistd.h>
> #include <sys/types.h>
> #include <sys/time.h>
>
> //#define SAFE
>
> extern "C" void* do_it(void*);
> int *now;
>
> #ifdef SAFE
> pthread_mutex_t throw_mut;
> #endif
>
> int
> main(int argc, char *argv[]) {
>   if (argc != 2) {
>     fprintf(stderr, "Usage: throw numthreads\n");
>     exit(1);
>   }
>
>   int numthreads = atoi(argv[1]);
>
> #ifdef SAFE
>   pthread_mutex_init(&throw_mut,NULL);
> #endif
>
>   now = new int[numthreads];
>   for(int i = 0; i<numthreads; i++) {
>     now[i] = 0;
>     pthread_t id;
>     pthread_create(&id,NULL,do_it,(void*)i);
>   }
>
>   while(1) {
>     struct timeval to = {0, 10000};
>     if (select(0, 0, 0, 0, &to) == -1) {
>       perror("select");
>       exit(1);
>     }
>     for (int i=0; i<numthreads; i++)
>       now[i] = 1;
>     }
>
>   return(0);
> }
>
> class Excp {
> public:
>   Excp() {}
> };
>
> void*
> do_it(void* arg) {
>
>   int me = (int) arg;
>   while(1) {
>     try {
>       while (1) {
>         if (now[me] == 1) {
>  #ifdef SAFE
>           pthread_mutex_lock(&throw_mut);
>  #endif
>           throw(Excp());
>         }
>       }
>     } catch (Excp &x) {
>       now[me] = 0;
>  #ifdef SAFE
>       pthread_mutex_unlock(&throw_mut);
>  #endif
>     }
>   }
>   return 0;
> }
>
> --
> Sai-Lai Lo                                   S.Lo@uk.research.att.com
> AT&T Laboratories Cambridge           WWW:   http://www.uk.research.att.com
> 24a Trumpington Street                Tel:   +44 1223 343000
> Cambridge CB2 1QA                     Fax:   +44 1223 313542
> ENGLAND
>
> ---

--
Arnault Bonafos     Software Engineer
Tumbleweed    Communications    Corp.
ph: (650) 216-2027  fx: (650) 216-2003



--------------2FBD8B74343F5A3E887A090C
Content-Type: text/html; charset=us-ascii
Content-Transfer-Encoding: 7bit

<!doctype html public "-//w3c//dtd html 4.0 transitional//en">
<html>
&nbsp;
<br>After having compiled (with SunCompiler 5.0) the Sai Lai Lo revised
program from the omniORB archive on a Ultra 5 Solaris2.7
<br>single processor machine (with all necessary patches), it appears that
this test works fine.
<br>The test machine is a SMP machine Solaris2.7, 4 processors, with the
OS related patches applied.
<br>Before applying the patches the program was not runnable because of
some linker issue.
<p>Can Sai Lai Lo confirm, or someone else, that this test is supposed
to fail (crash) on a unpatched SMP machine, the message seems to be clear,
I just want to confirm this point.
<br>Should the success of this test confirm the thread safety of SunCompiler
5.0?
<p>The patches applied to the SMP machine are:
<br>106327-08&nbsp; SunOS 5.7: Shared library patch for C++
<br>106748-04&nbsp; SunOS 5.7: /usr/ccs/bin/sccs and /usr/ccs/bin/make
patch
<p>The first patch lists "4005413 throw is not thread safe" as being solved
by the patch, for reminder this is the bug
<br>item that Sai Lai Lo pointed out in his message with the SMP test program.
<p>I've used exactly the same program that is copied thereafter, the number
of threads was 5 50 and 200.
<p>Sai-Lai Lo wrote:
<blockquote TYPE=CITE>Unfortunately, things are not as simple as it first
looks.
<br>I changed the test program to use pthread and corrected some obvious
<br>mistakes and it no longer SEGV.
<p>My omniorb test program still SEGV in exception unwinding though.
<p>Sai-Lai
<p>The revised test is as follows:
<p>#include &lt;pthread.h>
<br>#include &lt;stdio.h>
<br>#include &lt;stdlib.h>
<br>#include &lt;unistd.h>
<br>#include &lt;sys/types.h>
<br>#include &lt;sys/time.h>
<p>//#define SAFE
<p>extern "C" void* do_it(void*);
<br>int *now;
<p>#ifdef SAFE
<br>pthread_mutex_t throw_mut;
<br>#endif
<p>int
<br>main(int argc, char *argv[]) {
<br>&nbsp; if (argc != 2) {
<br>&nbsp;&nbsp;&nbsp; fprintf(stderr, "Usage: throw numthreads\n");
<br>&nbsp;&nbsp;&nbsp; exit(1);
<br>&nbsp; }
<p>&nbsp; int numthreads = atoi(argv[1]);
<p>#ifdef SAFE
<br>&nbsp; pthread_mutex_init(&amp;throw_mut,NULL);
<br>#endif
<p>&nbsp; now = new int[numthreads];
<br>&nbsp; for(int i = 0; i&lt;numthreads; i++) {
<br>&nbsp;&nbsp;&nbsp; now[i] = 0;
<br>&nbsp;&nbsp;&nbsp; pthread_t id;
<br>&nbsp;&nbsp;&nbsp; pthread_create(&amp;id,NULL,do_it,(void*)i);
<br>&nbsp; }
<p>&nbsp; while(1) {
<br>&nbsp;&nbsp;&nbsp; struct timeval to = {0, 10000};
<br>&nbsp;&nbsp;&nbsp; if (select(0, 0, 0, 0, &amp;to) == -1) {
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; perror("select");
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; exit(1);
<br>&nbsp;&nbsp;&nbsp; }
<br>&nbsp;&nbsp;&nbsp; for (int i=0; i&lt;numthreads; i++)
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; now[i] = 1;
<br>&nbsp;&nbsp;&nbsp; }
<p>&nbsp; return(0);
<br>}
<p>class Excp {
<br>public:
<br>&nbsp; Excp() {}
<br>};
<p>void*
<br>do_it(void* arg) {
<p>&nbsp; int me = (int) arg;
<br>&nbsp; while(1) {
<br>&nbsp;&nbsp;&nbsp; try {
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; while (1) {
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if (now[me] == 1) {
<br>&nbsp;#ifdef SAFE
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; pthread_mutex_lock(&amp;throw_mut);
<br>&nbsp;#endif
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; throw(Excp());
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }
<br>&nbsp;&nbsp;&nbsp; } catch (Excp &amp;x) {
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; now[me] = 0;
<br>&nbsp;#ifdef SAFE
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; pthread_mutex_unlock(&amp;throw_mut);
<br>&nbsp;#endif
<br>&nbsp;&nbsp;&nbsp; }
<br>&nbsp; }
<br>&nbsp; return 0;
<br>}
<p>--
<br>Sai-Lai Lo&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
S.Lo@uk.research.att.com
<br>AT&amp;T Laboratories Cambridge&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
WWW:&nbsp;&nbsp; <a href="http://www.uk.research.att.com">http://www.uk.research.att.com</a>
<br>24a Trumpington Street&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
Tel:&nbsp;&nbsp; +44 1223 343000
<br>Cambridge CB2 1QA&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
Fax:&nbsp;&nbsp; +44 1223 313542
<br>ENGLAND
<p>---</blockquote>

<pre>--&nbsp;
Arnault Bonafos&nbsp;&nbsp;&nbsp;&nbsp; Software Engineer
Tumbleweed&nbsp;&nbsp;&nbsp; Communications&nbsp;&nbsp;&nbsp; Corp.
ph: (650) 216-2027&nbsp; fx: (650) 216-2003</pre>
&nbsp;</html>

--------------2FBD8B74343F5A3E887A090C--