<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Problems with simple threaded program in Operating System - OpenVMS</title>
    <link>https://community.hpe.com/t5/operating-system-openvms/problems-with-simple-threaded-program/m-p/4302992#M44810</link>
    <description>If we're exchanging aphorisms, remember that thread-safe is an oxymoron.   And that per-thread security probably isn't.&lt;BR /&gt;&lt;BR /&gt;And slightly more seriously, having $hiber and $wake flying around in any application can snarl an AST-driven or a thread-based program.</description>
    <pubDate>Tue, 11 Nov 2008 14:48:40 GMT</pubDate>
    <dc:creator>Hoff</dc:creator>
    <dc:date>2008-11-11T14:48:40Z</dc:date>
    <item>
      <title>Problems with simple threaded program</title>
      <link>https://community.hpe.com/t5/operating-system-openvms/problems-with-simple-threaded-program/m-p/4302980#M44798</link>
      <description>Hello!&lt;BR /&gt;Please help to point me to my error:&lt;BR /&gt;&lt;BR /&gt;This is simple code:&lt;BR /&gt;&lt;BR /&gt;#include &lt;STDIO.H&gt;&lt;BR /&gt;#include &lt;PTHREAD.H&gt;&lt;BR /&gt;#define NUM 5&lt;BR /&gt;&lt;BR /&gt;main()&lt;BR /&gt;{&lt;BR /&gt;pthread_t t1,t2;&lt;BR /&gt;&lt;BR /&gt;void *print_msg(void *);&lt;BR /&gt;&lt;BR /&gt;pthread_create(&amp;amp;t1,NULL, print_msg, (void *)"hello");&lt;BR /&gt;pthread_create(&amp;amp;t2,NULL, print_msg, (void *)"world\n");&lt;BR /&gt;pthread_join(t1,NULL);&lt;BR /&gt;printf("end1\n");&lt;BR /&gt;pthread_join(t2,NULL);&lt;BR /&gt;}&lt;BR /&gt;&lt;BR /&gt;void *print_msg(void *m)&lt;BR /&gt;{&lt;BR /&gt;  char *s = (char *)m;&lt;BR /&gt;&lt;BR /&gt;  printf("%s",s);&lt;BR /&gt;  fflush(stdout);&lt;BR /&gt;  sleep(1);&lt;BR /&gt;&lt;BR /&gt;  printf("%s",s);&lt;BR /&gt;  fflush(stdout);&lt;BR /&gt;  sleep(1);&lt;BR /&gt;&lt;BR /&gt;  printf("%s",s);&lt;BR /&gt;  fflush(stdout);&lt;BR /&gt;  sleep(1);&lt;BR /&gt;&lt;BR /&gt;  printf("%s",s);&lt;BR /&gt;  fflush(stdout);&lt;BR /&gt;  sleep(1);&lt;BR /&gt;&lt;BR /&gt;  printf("%s",s);&lt;BR /&gt;  fflush(stdout);&lt;BR /&gt;  sleep(1);&lt;BR /&gt;&lt;BR /&gt;return NULL;&lt;BR /&gt;}&lt;BR /&gt;&lt;BR /&gt;&lt;/PTHREAD.H&gt;&lt;/STDIO.H&gt;</description>
      <pubDate>Sun, 09 Nov 2008 16:20:08 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-openvms/problems-with-simple-threaded-program/m-p/4302980#M44798</guid>
      <dc:creator>Alex Chupahin</dc:creator>
      <dc:date>2008-11-09T16:20:08Z</dc:date>
    </item>
    <item>
      <title>Re: Problems with simple threaded program</title>
      <link>https://community.hpe.com/t5/operating-system-openvms/problems-with-simple-threaded-program/m-p/4302981#M44799</link>
      <description>When I start it:&lt;BR /&gt;$ru simple&lt;BR /&gt;&lt;BR /&gt;helloworld&lt;BR /&gt;helloworld&lt;BR /&gt;world&lt;BR /&gt;helloworld&lt;BR /&gt;helloworld&lt;BR /&gt;hello&lt;BR /&gt;&lt;BR /&gt;and then program freezes. I can exit via ctrl-C only.&lt;BR /&gt;What I forget or doing wrong?</description>
      <pubDate>Sun, 09 Nov 2008 16:34:29 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-openvms/problems-with-simple-threaded-program/m-p/4302981#M44799</guid>
      <dc:creator>Alex Chupahin</dc:creator>
      <dc:date>2008-11-09T16:34:29Z</dc:date>
    </item>
    <item>
      <title>Re: Problems with simple threaded program</title>
      <link>https://community.hpe.com/t5/operating-system-openvms/problems-with-simple-threaded-program/m-p/4302982#M44800</link>
      <description>I don't currently have access to a system to test but, from memory, I think you may need to call&lt;BR /&gt;&lt;BR /&gt;pthread_exit(0);&lt;BR /&gt;&lt;BR /&gt;just prior to your&lt;BR /&gt;&lt;BR /&gt;return NULL;&lt;BR /&gt;&lt;BR /&gt;in print_msg().</description>
      <pubDate>Sun, 09 Nov 2008 17:10:21 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-openvms/problems-with-simple-threaded-program/m-p/4302982#M44800</guid>
      <dc:creator>Jim_McKinney</dc:creator>
      <dc:date>2008-11-09T17:10:21Z</dc:date>
    </item>
    <item>
      <title>Re: Problems with simple threaded program</title>
      <link>https://community.hpe.com/t5/operating-system-openvms/problems-with-simple-threaded-program/m-p/4302983#M44801</link>
      <description>Thank you, but during experimentation, I have added pthread_exit function before return. Without success.&lt;BR /&gt;</description>
      <pubDate>Sun, 09 Nov 2008 17:36:56 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-openvms/problems-with-simple-threaded-program/m-p/4302983#M44801</guid>
      <dc:creator>Alex Chupahin</dc:creator>
      <dc:date>2008-11-09T17:36:56Z</dc:date>
    </item>
    <item>
      <title>Re: Problems with simple threaded program</title>
      <link>https://community.hpe.com/t5/operating-system-openvms/problems-with-simple-threaded-program/m-p/4302984#M44802</link>
      <description>Alex,&lt;BR /&gt;&lt;BR /&gt; what are you expecting the main program to do while the threads are running? I wouldn't expect this program to hang, I'd expect it to just exit (like the code says). Maybe you need a sleep before the end? First cut I'd add sleep(10) after the second pthread_join so you know the main thread will still be around when the threads complete. Better would be to use the pthread routine to synchronize with the completions of each executing thread. &lt;BR /&gt;&lt;BR /&gt;  What about the printf in main? Should that have an fflush too?</description>
      <pubDate>Sun, 09 Nov 2008 20:19:25 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-openvms/problems-with-simple-threaded-program/m-p/4302984#M44802</guid>
      <dc:creator>John Gillings</dc:creator>
      <dc:date>2008-11-09T20:19:25Z</dc:date>
    </item>
    <item>
      <title>Re: Problems with simple threaded program</title>
      <link>https://community.hpe.com/t5/operating-system-openvms/problems-with-simple-threaded-program/m-p/4302985#M44803</link>
      <description>John I expect my program will be successfully finished and exit. But it doesnt. I should press ctrl-C to exit.  printf() in main() between pthread_join is not working.&lt;BR /&gt;</description>
      <pubDate>Sun, 09 Nov 2008 20:24:38 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-openvms/problems-with-simple-threaded-program/m-p/4302985#M44803</guid>
      <dc:creator>Alex Chupahin</dc:creator>
      <dc:date>2008-11-09T20:24:38Z</dc:date>
    </item>
    <item>
      <title>Re: Problems with simple threaded program</title>
      <link>https://community.hpe.com/t5/operating-system-openvms/problems-with-simple-threaded-program/m-p/4302986#M44804</link>
      <description>LINK /THREAD=UP</description>
      <pubDate>Sun, 09 Nov 2008 23:23:51 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-openvms/problems-with-simple-threaded-program/m-p/4302986#M44804</guid>
      <dc:creator>Hoff</dc:creator>
      <dc:date>2008-11-09T23:23:51Z</dc:date>
    </item>
    <item>
      <title>Re: Problems with simple threaded program</title>
      <link>https://community.hpe.com/t5/operating-system-openvms/problems-with-simple-threaded-program/m-p/4302987#M44805</link>
      <description>Thank you, Hoff!&lt;BR /&gt;</description>
      <pubDate>Mon, 10 Nov 2008 07:14:43 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-openvms/problems-with-simple-threaded-program/m-p/4302987#M44805</guid>
      <dc:creator>Alex Chupahin</dc:creator>
      <dc:date>2008-11-10T07:14:43Z</dc:date>
    </item>
    <item>
      <title>Re: Problems with simple threaded program</title>
      <link>https://community.hpe.com/t5/operating-system-openvms/problems-with-simple-threaded-program/m-p/4302988#M44806</link>
      <description>Hi, Alex!&lt;BR /&gt;&lt;BR /&gt; First at all you need to be ensure that the treads has been created with JOINABLE attributes (a default JOINABLE/DETACHED attribute depends frov OS version and platform).&lt;BR /&gt;&lt;BR /&gt;I suggest to check threads state with SDA:&lt;BR /&gt;ana/sys&lt;BR /&gt;SDA&amp;gt;set proc /id=&lt;PID&gt;&lt;BR /&gt;SDA&amp;gt;pthread thread [-f]&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;sleep() - is not reenterable routine, you should use pthread_delay_np()&lt;/PID&gt;</description>
      <pubDate>Mon, 10 Nov 2008 09:40:39 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-openvms/problems-with-simple-threaded-program/m-p/4302988#M44806</guid>
      <dc:creator>Ruslan R. Laishev</dc:creator>
      <dc:date>2008-11-10T09:40:39Z</dc:date>
    </item>
    <item>
      <title>Re: Problems with simple threaded program</title>
      <link>https://community.hpe.com/t5/operating-system-openvms/problems-with-simple-threaded-program/m-p/4302989#M44807</link>
      <description>Hoff that was your shortest reply ever and it was worth 10 points a character!  lol&lt;BR /&gt;</description>
      <pubDate>Mon, 10 Nov 2008 14:26:17 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-openvms/problems-with-simple-threaded-program/m-p/4302989#M44807</guid>
      <dc:creator>EdgarZamora_1</dc:creator>
      <dc:date>2008-11-10T14:26:17Z</dc:date>
    </item>
    <item>
      <title>Re: Problems with simple threaded program</title>
      <link>https://community.hpe.com/t5/operating-system-openvms/problems-with-simple-threaded-program/m-p/4302990#M44808</link>
      <description>Spasibo, Ruslan!&lt;BR /&gt;Eto tozhe vazhno.&lt;BR /&gt;</description>
      <pubDate>Tue, 11 Nov 2008 06:11:44 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-openvms/problems-with-simple-threaded-program/m-p/4302990#M44808</guid>
      <dc:creator>Alex Chupahin</dc:creator>
      <dc:date>2008-11-11T06:11:44Z</dc:date>
    </item>
    <item>
      <title>Re: Problems with simple threaded program</title>
      <link>https://community.hpe.com/t5/operating-system-openvms/problems-with-simple-threaded-program/m-p/4302991#M44809</link>
      <description>Hi, Alex!&lt;BR /&gt;&lt;BR /&gt;Using link/thread=(upcalls[,mult]) is not essential for normal behaviour of threads. :-)</description>
      <pubDate>Tue, 11 Nov 2008 07:29:09 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-openvms/problems-with-simple-threaded-program/m-p/4302991#M44809</guid>
      <dc:creator>Ruslan R. Laishev</dc:creator>
      <dc:date>2008-11-11T07:29:09Z</dc:date>
    </item>
    <item>
      <title>Re: Problems with simple threaded program</title>
      <link>https://community.hpe.com/t5/operating-system-openvms/problems-with-simple-threaded-program/m-p/4302992#M44810</link>
      <description>If we're exchanging aphorisms, remember that thread-safe is an oxymoron.   And that per-thread security probably isn't.&lt;BR /&gt;&lt;BR /&gt;And slightly more seriously, having $hiber and $wake flying around in any application can snarl an AST-driven or a thread-based program.</description>
      <pubDate>Tue, 11 Nov 2008 14:48:40 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-openvms/problems-with-simple-threaded-program/m-p/4302992#M44810</guid>
      <dc:creator>Hoff</dc:creator>
      <dc:date>2008-11-11T14:48:40Z</dc:date>
    </item>
    <item>
      <title>Re: Problems with simple threaded program</title>
      <link>https://community.hpe.com/t5/operating-system-openvms/problems-with-simple-threaded-program/m-p/4302993#M44811</link>
      <description>Agreed. :-)</description>
      <pubDate>Tue, 11 Nov 2008 14:50:36 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-openvms/problems-with-simple-threaded-program/m-p/4302993#M44811</guid>
      <dc:creator>Ruslan R. Laishev</dc:creator>
      <dc:date>2008-11-11T14:50:36Z</dc:date>
    </item>
    <item>
      <title>Re: Problems with simple threaded program</title>
      <link>https://community.hpe.com/t5/operating-system-openvms/problems-with-simple-threaded-program/m-p/4302994#M44812</link>
      <description>Without the LINK/THREAD=UPCALLS the the threads interfere with each others sleep(). Eventually one $WAKE is lost and the process hange in HIB. Check the return value from sleep(). It's not always 0 meaning the sleep() returned earlier. That's the $WAKE (part of the sleep() implementation) that finally is missing.&lt;BR /&gt;&lt;BR /&gt;/Guenther</description>
      <pubDate>Tue, 11 Nov 2008 23:25:34 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-openvms/problems-with-simple-threaded-program/m-p/4302994#M44812</guid>
      <dc:creator>GuentherF</dc:creator>
      <dc:date>2008-11-11T23:25:34Z</dc:date>
    </item>
    <item>
      <title>Re: Problems with simple threaded program</title>
      <link>https://community.hpe.com/t5/operating-system-openvms/problems-with-simple-threaded-program/m-p/4302995#M44813</link>
      <description>Back when I was more regularly tossing $hiber and $wake calls and ASTs around (and this was back in the era when the debugger itself would interfere with $hiber and $wake), a periodic $schdwk was a handy thing to have chugging along in the background.  This was a deliberately-induced spurious wake-up, and it did tend to unwedge things until you could figure out what really happened.&lt;BR /&gt;&lt;BR /&gt;(This all seems so primitive now.  Ah, well.)&lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Tue, 11 Nov 2008 23:54:56 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-openvms/problems-with-simple-threaded-program/m-p/4302995#M44813</guid>
      <dc:creator>Hoff</dc:creator>
      <dc:date>2008-11-11T23:54:56Z</dc:date>
    </item>
    <item>
      <title>Re: Problems with simple threaded program</title>
      <link>https://community.hpe.com/t5/operating-system-openvms/problems-with-simple-threaded-program/m-p/4302996#M44814</link>
      <description>$HIBER / $WAKE in a multi-threaded program: Isn't that asking for trouble? IIRC, it used to be discouraged; but things may have chnaged in the years...</description>
      <pubDate>Wed, 12 Nov 2008 11:09:04 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-openvms/problems-with-simple-threaded-program/m-p/4302996#M44814</guid>
      <dc:creator>Willem Grooters</dc:creator>
      <dc:date>2008-11-12T11:09:04Z</dc:date>
    </item>
  </channel>
</rss>

