Re: pthread_spin_lock

[email protected] Wed, 31 Jan 2007 23:00:05 +0200
Newsgroups gmane.linux.real-time.rtlinux.general
Message-ID <[email protected]>
--===============1449969863==
Content-Type: multipart/alternative; 
	boundary="----=_Part_11683_14698226.1170277205918"

------=_Part_11683_14698226.1170277205918
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding: 7bit
Content-Disposition: inline

Not an SMP box actually. I was trying to test my box's capabilities
according to Dr. Dobb's article (http://www.ddj.com/dept/cpp/184401780)

But this one works:

*(a)*
Thread A
   pthread_spin_lock(&lock);
   sem_post(&sem);
   clock_gettime(CLOCK_REALTIME, &start);
   pthread_spin_unlock(&lock);
Thread B
   sem_wait(&start_sem);
   pthread_spin_lock(&lock);
   clock_gettime(CLOCK_REALTIME, &end);
   pthread_spin_unlock(&lock);

I don't understood the meaning of semaphore usage so I coded without them.
sem_post doesn't make switching to threadB immediately. One way is making
ThreadB higher priority but it makes latency latency higher. I tried it with
mutex instead of spinlock.

thank you

On 1/31/07, [email protected] <[email protected]> wrote:
>
> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA1
>
> >
> > According to man page of pthread_spin_lock "As the context switch
> overhead
> > is saved, spinlocks usually give better performance on multi-processor
> > systems than other synchronization methods"
> >
> > When i use spinlock for task syncing, it locks my box.
> >
> > threadA()
> > {
> > while(1)
> > {
> >   pthread_wait_np();
> >   pthread_spin_lock(&lock);
> >   ...
> >   pthread_spin_unlock(&lock);
> > }
> > }
> >
> > threadB()
> > {
> > while(1)
> > {
> >   pthread_spin(&lock);
> >   ....
> >   pthread_spin_unlock(&lock);
> > }
> > }
> >
> > Whats is wrong am I doing ?
> > Thank you.
> >
> Are you running on a SMP box and is it configured as SMP ?
>
> hofrat
> -----BEGIN PGP SIGNATURE-----
> Version: GnuPG v1.2.4 (GNU/Linux)
>
> iD8DBQFFwCPXnU7rXZKfY2oRAlWbAJ46RUa39m6HyIGgs7uQPeJEIwGQ2wCfdzID
> 94sXzqv0z3+g7rgZiT2bZNI=
> =p1ZX
> -----END PGP SIGNATURE-----
> _______________________________________________
> Rtl mailing list
> [email protected]
> http://hq.fsmlabs.com/mailman/listinfo/rtl
> http:/www.rtlinux-gpl.org/
>

------=_Part_11683_14698226.1170277205918
Content-Type: text/html; charset=ISO-8859-1
Content-Transfer-Encoding: 7bit
Content-Disposition: inline

Not an SMP box actually. I was trying to test my box&#39;s capabilities according to Dr. Dobb&#39;s article (<a href="http://www.ddj.com/dept/cpp/184401780">http://www.ddj.com/dept/cpp/184401780</a>)<br><br>But this one works:
<br><pre><b>(a)</b><br>Thread A<br>   pthread_spin_lock(&amp;lock);<br>   sem_post(&amp;sem);<br>   clock_gettime(CLOCK_REALTIME, &amp;start);<br>   pthread_spin_unlock(&amp;lock);<br>Thread B<br>   sem_wait(&amp;start_sem);
<br>   pthread_spin_lock(&amp;lock);<br>   clock_gettime(CLOCK_REALTIME, &amp;end);<br>   pthread_spin_unlock(&amp;lock);<br><br></pre>I don&#39;t understood the meaning of semaphore usage so I coded without them. sem_post doesn&#39;t make switching to threadB immediately. One way is making ThreadB higher priority but it makes latency latency higher. I tried it with mutex instead of spinlock.
<br><br>thank you<br><br><div><span class="gmail_quote">On 1/31/07, <b class="gmail_sendername"><a href="mailto:[email protected]">[email protected]</a></b> &lt;<a href="mailto:[email protected]">[email protected]</a>&gt; wrote:</span>
<blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">-----BEGIN PGP SIGNED MESSAGE-----<br>Hash: SHA1<br><br>&gt;<br>&gt; According to man page of pthread_spin_lock &quot;As the context switch overhead
<br>&gt; is saved, spinlocks usually give better performance on multi-processor<br>&gt; systems than other synchronization methods&quot;<br>&gt;<br>&gt; When i use spinlock for task syncing, it locks my box.<br>&gt;<br>&gt; threadA()
<br>&gt; {<br>&gt; while(1)<br>&gt; {<br>&gt;&nbsp;&nbsp; pthread_wait_np();<br>&gt;&nbsp;&nbsp; pthread_spin_lock(&amp;lock);<br>&gt;&nbsp;&nbsp; ...<br>&gt;&nbsp;&nbsp; pthread_spin_unlock(&amp;lock);<br>&gt; }<br>&gt; }<br>&gt;<br>&gt; threadB()<br>&gt; {<br>
&gt; while(1)<br>&gt; {<br>&gt;&nbsp;&nbsp; pthread_spin(&amp;lock);<br>&gt;&nbsp;&nbsp; ....<br>&gt;&nbsp;&nbsp; pthread_spin_unlock(&amp;lock);<br>&gt; }<br>&gt; }<br>&gt;<br>&gt; Whats is wrong am I doing ?<br>&gt; Thank you.<br>&gt;<br>Are you running on a SMP box and is it configured as SMP ?
<br><br>hofrat<br>-----BEGIN PGP SIGNATURE-----<br>Version: GnuPG v1.2.4 (GNU/Linux)<br><br>iD8DBQFFwCPXnU7rXZKfY2oRAlWbAJ46RUa39m6HyIGgs7uQPeJEIwGQ2wCfdzID<br>94sXzqv0z3+g7rgZiT2bZNI=<br>=p1ZX<br>-----END PGP SIGNATURE-----
<br>_______________________________________________<br>Rtl mailing list<br><a href="mailto:[email protected]">[email protected]</a><br><a href="http://hq.fsmlabs.com/mailman/listinfo/rtl">http://hq.fsmlabs.com/mailman/listinfo/rtl
</a><br>http:/www.rtlinux-<a href="http://gpl.org/">gpl.org/</a><br></blockquote></div><br>

------=_Part_11683_14698226.1170277205918--

--===============1449969863==
Content-Type: text/plain; charset="us-ascii"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Content-Disposition: inline

_______________________________________________
Rtl mailing list
[email protected]
http://hq.fsmlabs.com/mailman/listinfo/rtl
http:/www.rtlinux-gpl.org/
--===============1449969863==--