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's capabilities according to Dr. Dobb'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(&lock);<br> sem_post(&sem);<br> clock_gettime(CLOCK_REALTIME, &start);<br> pthread_spin_unlock(&lock);<br>Thread B<br> sem_wait(&start_sem); <br> pthread_spin_lock(&lock);<br> clock_gettime(CLOCK_REALTIME, &end);<br> pthread_spin_unlock(&lock);<br><br></pre>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. <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> <<a href="mailto:[email protected]">[email protected]</a>> 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>><br>> According to man page of pthread_spin_lock "As the context switch overhead <br>> is saved, spinlocks usually give better performance on multi-processor<br>> systems than other synchronization methods"<br>><br>> When i use spinlock for task syncing, it locks my box.<br>><br>> threadA() <br>> {<br>> while(1)<br>> {<br>> pthread_wait_np();<br>> pthread_spin_lock(&lock);<br>> ...<br>> pthread_spin_unlock(&lock);<br>> }<br>> }<br>><br>> threadB()<br>> {<br> > while(1)<br>> {<br>> pthread_spin(&lock);<br>> ....<br>> pthread_spin_unlock(&lock);<br>> }<br>> }<br>><br>> Whats is wrong am I doing ?<br>> Thank you.<br>><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==--