<?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 need immediate help about semaphore synchronization. in Operating System - HP-UX</title>
    <link>https://community.hpe.com/t5/operating-system-hp-ux/need-immediate-help-about-semaphore-synchronization/m-p/3968308#M757907</link>
    <description>I can't solve the problem in this producer consumer problem for printer spooling.&lt;BR /&gt;&lt;BR /&gt;void *printer(void *args) //producer&lt;BR /&gt;{&lt;BR /&gt;int holder_1,i;&lt;BR /&gt;&lt;BR /&gt;while (general_counter &amp;lt; n)&lt;BR /&gt;{&lt;BR /&gt;sem_wait(&amp;amp;queues);&lt;BR /&gt;&lt;BR /&gt;sem_wait(&amp;amp;mutex);&lt;BR /&gt; holder_1=dequeue(&amp;amp;q);&lt;BR /&gt; dequeue_counter++;&lt;BR /&gt;sem_post(&amp;amp;mutex);&lt;BR /&gt;&lt;BR /&gt;printf("Job(%d) starts printing with %dK. (%.3f seconds left.)\n", dequeue_counter, holder_1, (float)holder_1*0.01); &lt;BR /&gt;&lt;BR /&gt;for(i=0; i&lt;HOLDER_1&gt;&lt;/HOLDER_1&gt;  {&lt;BR /&gt;   usleep(10000);&lt;BR /&gt;   time_complete=time_complete-0.01;&lt;BR /&gt;   sem_post(&amp;amp;full);&lt;BR /&gt;  }&lt;BR /&gt;&lt;BR /&gt;printf("Job(%d) completed printing.\n", dequeue_counter);&lt;BR /&gt;&lt;BR /&gt;sem_wait(&amp;amp;mutex);&lt;BR /&gt;general_counter++;&lt;BR /&gt;sem_post(&amp;amp;mutex);&lt;BR /&gt;&lt;BR /&gt;}&lt;BR /&gt;&lt;BR /&gt;return NULL;&lt;BR /&gt;}&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;void *consumer_job(void *args) //consumer&lt;BR /&gt;{&lt;BR /&gt;int consume_value, i;&lt;BR /&gt;&lt;BR /&gt;consume_value=rand()%1024 + 50;  &lt;BR /&gt;&lt;BR /&gt;printf("A new job arrived with %dKb.\n", consume_value);&lt;BR /&gt;&lt;BR /&gt;for(i=0; i&lt;CONSUME_VALUE&gt;&lt;/CONSUME_VALUE&gt;   sem_wait(&amp;amp;full);&lt;BR /&gt;&lt;BR /&gt;time_complete=time_complete + (float)(consume_value * 0.01);  &lt;BR /&gt;&lt;BR /&gt;sem_wait(&amp;amp;mutex);&lt;BR /&gt;   enqueue(&amp;amp;q, consume_value);&lt;BR /&gt;   enqueue_counter++;&lt;BR /&gt;   printf("Job(%d) with %dKb enqued. %.3f seconds left to start.\n", enqueue_counter, consume_value, time_complete-(float)(consume_value * 0.01));&lt;BR /&gt;   sem_post(&amp;amp;queues); &lt;BR /&gt;sem_post(&amp;amp;mutex);&lt;BR /&gt;&lt;BR /&gt;return NULL;&lt;BR /&gt;}&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;Problem is that when the queue is empty and and the FULL semaphore value is 0, it enters to a deadlock. I can't think anything. :(&lt;BR /&gt;&lt;BR /&gt;If anyone has any idea about how I can fix it, I would be appreciate...</description>
    <pubDate>Sat, 24 Mar 2007 11:11:34 GMT</pubDate>
    <dc:creator>Osman Yagmurdereli</dc:creator>
    <dc:date>2007-03-24T11:11:34Z</dc:date>
    <item>
      <title>need immediate help about semaphore synchronization.</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/need-immediate-help-about-semaphore-synchronization/m-p/3968308#M757907</link>
      <description>I can't solve the problem in this producer consumer problem for printer spooling.&lt;BR /&gt;&lt;BR /&gt;void *printer(void *args) //producer&lt;BR /&gt;{&lt;BR /&gt;int holder_1,i;&lt;BR /&gt;&lt;BR /&gt;while (general_counter &amp;lt; n)&lt;BR /&gt;{&lt;BR /&gt;sem_wait(&amp;amp;queues);&lt;BR /&gt;&lt;BR /&gt;sem_wait(&amp;amp;mutex);&lt;BR /&gt; holder_1=dequeue(&amp;amp;q);&lt;BR /&gt; dequeue_counter++;&lt;BR /&gt;sem_post(&amp;amp;mutex);&lt;BR /&gt;&lt;BR /&gt;printf("Job(%d) starts printing with %dK. (%.3f seconds left.)\n", dequeue_counter, holder_1, (float)holder_1*0.01); &lt;BR /&gt;&lt;BR /&gt;for(i=0; i&lt;HOLDER_1&gt;&lt;/HOLDER_1&gt;  {&lt;BR /&gt;   usleep(10000);&lt;BR /&gt;   time_complete=time_complete-0.01;&lt;BR /&gt;   sem_post(&amp;amp;full);&lt;BR /&gt;  }&lt;BR /&gt;&lt;BR /&gt;printf("Job(%d) completed printing.\n", dequeue_counter);&lt;BR /&gt;&lt;BR /&gt;sem_wait(&amp;amp;mutex);&lt;BR /&gt;general_counter++;&lt;BR /&gt;sem_post(&amp;amp;mutex);&lt;BR /&gt;&lt;BR /&gt;}&lt;BR /&gt;&lt;BR /&gt;return NULL;&lt;BR /&gt;}&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;void *consumer_job(void *args) //consumer&lt;BR /&gt;{&lt;BR /&gt;int consume_value, i;&lt;BR /&gt;&lt;BR /&gt;consume_value=rand()%1024 + 50;  &lt;BR /&gt;&lt;BR /&gt;printf("A new job arrived with %dKb.\n", consume_value);&lt;BR /&gt;&lt;BR /&gt;for(i=0; i&lt;CONSUME_VALUE&gt;&lt;/CONSUME_VALUE&gt;   sem_wait(&amp;amp;full);&lt;BR /&gt;&lt;BR /&gt;time_complete=time_complete + (float)(consume_value * 0.01);  &lt;BR /&gt;&lt;BR /&gt;sem_wait(&amp;amp;mutex);&lt;BR /&gt;   enqueue(&amp;amp;q, consume_value);&lt;BR /&gt;   enqueue_counter++;&lt;BR /&gt;   printf("Job(%d) with %dKb enqued. %.3f seconds left to start.\n", enqueue_counter, consume_value, time_complete-(float)(consume_value * 0.01));&lt;BR /&gt;   sem_post(&amp;amp;queues); &lt;BR /&gt;sem_post(&amp;amp;mutex);&lt;BR /&gt;&lt;BR /&gt;return NULL;&lt;BR /&gt;}&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;Problem is that when the queue is empty and and the FULL semaphore value is 0, it enters to a deadlock. I can't think anything. :(&lt;BR /&gt;&lt;BR /&gt;If anyone has any idea about how I can fix it, I would be appreciate...</description>
      <pubDate>Sat, 24 Mar 2007 11:11:34 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/need-immediate-help-about-semaphore-synchronization/m-p/3968308#M757907</guid>
      <dc:creator>Osman Yagmurdereli</dc:creator>
      <dc:date>2007-03-24T11:11:34Z</dc:date>
    </item>
    <item>
      <title>Re: need immediate help about semaphore synchronization.</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/need-immediate-help-about-semaphore-synchronization/m-p/3968309#M757909</link>
      <description>semaphore FULL is initialized to 2048. (source)&lt;BR /&gt;semaphore MUTEX is initialized to 1.&lt;BR /&gt;semaphore QUEUE is initialized to 0.</description>
      <pubDate>Sat, 24 Mar 2007 11:13:35 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/need-immediate-help-about-semaphore-synchronization/m-p/3968309#M757909</guid>
      <dc:creator>Osman Yagmurdereli</dc:creator>
      <dc:date>2007-03-24T11:13:35Z</dc:date>
    </item>
    <item>
      <title>Re: need immediate help about semaphore synchronization.</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/need-immediate-help-about-semaphore-synchronization/m-p/3968310#M757911</link>
      <description>Should be be doing a post of queues before the post of mutex?&lt;BR /&gt;&lt;BR /&gt;You also seem to be doing a random number of wait on full, is this passed to the producer to do that number of posts?&lt;BR /&gt;&lt;BR /&gt;(Any reason you are casting to float instead of double?)</description>
      <pubDate>Sun, 25 Mar 2007 22:35:21 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/need-immediate-help-about-semaphore-synchronization/m-p/3968310#M757911</guid>
      <dc:creator>Dennis Handly</dc:creator>
      <dc:date>2007-03-25T22:35:21Z</dc:date>
    </item>
  </channel>
</rss>

