 
<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
		<id>https://www.adonaimedrado.pro.br/wiki/index.php?action=history&amp;feed=atom&amp;title=C%3A_Deadlock</id>
		<title>C: Deadlock - Revision history</title>
		<link rel="self" type="application/atom+xml" href="https://www.adonaimedrado.pro.br/wiki/index.php?action=history&amp;feed=atom&amp;title=C%3A_Deadlock"/>
		<link rel="alternate" type="text/html" href="https://www.adonaimedrado.pro.br/wiki/index.php?title=C:_Deadlock&amp;action=history"/>
		<updated>2026-05-27T19:06:59Z</updated>
		<subtitle>Revision history for this page on the wiki</subtitle>
		<generator>MediaWiki 1.26.2</generator>

	<entry>
		<id>https://www.adonaimedrado.pro.br/wiki/index.php?title=C:_Deadlock&amp;diff=3649&amp;oldid=prev</id>
		<title>Adonaimedrado: Created page with '&lt;code lang=&quot;c&quot;&gt; #include &lt;stdio.h&gt; #include &lt;pthread.h&gt;  int x; pthread_mutex_t mutex_de_x, mutex_de_y;  void *minha_thread1(void *null) {	 	pthread_mutex_lock(&amp;mutex_de_x); 		pr…'</title>
		<link rel="alternate" type="text/html" href="https://www.adonaimedrado.pro.br/wiki/index.php?title=C:_Deadlock&amp;diff=3649&amp;oldid=prev"/>
				<updated>2010-08-28T07:13:41Z</updated>
		
		<summary type="html">&lt;p&gt;Created page with &amp;#039;&amp;lt;code lang=&amp;quot;c&amp;quot;&amp;gt; #include &amp;lt;stdio.h&amp;gt; #include &amp;lt;pthread.h&amp;gt;  int x; pthread_mutex_t mutex_de_x, mutex_de_y;  void *minha_thread1(void *null) {	 	pthread_mutex_lock(&amp;amp;mutex_de_x); 		pr…&amp;#039;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;&amp;lt;code lang=&amp;quot;c&amp;quot;&amp;gt;&lt;br /&gt;
#include &amp;lt;stdio.h&amp;gt;&lt;br /&gt;
#include &amp;lt;pthread.h&amp;gt;&lt;br /&gt;
&lt;br /&gt;
int x;&lt;br /&gt;
pthread_mutex_t mutex_de_x, mutex_de_y;&lt;br /&gt;
&lt;br /&gt;
void *minha_thread1(void *null)&lt;br /&gt;
{	&lt;br /&gt;
	pthread_mutex_lock(&amp;amp;mutex_de_x);&lt;br /&gt;
		printf(&amp;quot;minha_thread1: Obtive acesso ao mutex X.\n&amp;quot;);&lt;br /&gt;
		printf(&amp;quot;minha_thread1: Aguardando 1 segundo...\n&amp;quot;);&lt;br /&gt;
		sleep(1);&lt;br /&gt;
		printf(&amp;quot;minha_thread1: Tentando mutex Y...\n&amp;quot;);		&lt;br /&gt;
		pthread_mutex_lock(&amp;amp;mutex_de_y);&lt;br /&gt;
			printf(&amp;quot;minha_thread1: Obtive acesso ao mutex Y.\n&amp;quot;);&lt;br /&gt;
			printf(&amp;quot;minha_thread1: Liberando mutex Y...\n&amp;quot;);&lt;br /&gt;
		pthread_mutex_unlock(&amp;amp;mutex_de_y);&lt;br /&gt;
		printf(&amp;quot;minha_thread1: Liberando mutex X...\n&amp;quot;);&lt;br /&gt;
	pthread_mutex_unlock(&amp;amp;mutex_de_x);&lt;br /&gt;
	&lt;br /&gt;
	pthread_exit(NULL);&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
void *minha_thread2(void *null)&lt;br /&gt;
{	&lt;br /&gt;
	pthread_mutex_lock(&amp;amp;mutex_de_y);&lt;br /&gt;
		printf(&amp;quot;minha_thread2: Obtive acesso ao mutex Y.\n&amp;quot;);&lt;br /&gt;
		printf(&amp;quot;minha_thread2: Aguardando 1 segundo...\n&amp;quot;);&lt;br /&gt;
		sleep(1);&lt;br /&gt;
		printf(&amp;quot;minha_thread2: Tentando mutex X...\n&amp;quot;);		&lt;br /&gt;
		pthread_mutex_lock(&amp;amp;mutex_de_x);&lt;br /&gt;
			printf(&amp;quot;minha_thread2: Obtive acesso ao mutex X.\n&amp;quot;);&lt;br /&gt;
			printf(&amp;quot;minha_thread2: Liberando mutex X...\n&amp;quot;);&lt;br /&gt;
		pthread_mutex_unlock(&amp;amp;mutex_de_x);&lt;br /&gt;
		printf(&amp;quot;minha_thread2: Liberando mutex Y...\n&amp;quot;);&lt;br /&gt;
	pthread_mutex_unlock(&amp;amp;mutex_de_y);&lt;br /&gt;
	&lt;br /&gt;
&lt;br /&gt;
	pthread_exit(NULL);&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
int main()&lt;br /&gt;
{&lt;br /&gt;
	int retorno_da_thread;&lt;br /&gt;
	pthread_t thread1, thread2;&lt;br /&gt;
	pthread_attr_t atributo_de_thread;&lt;br /&gt;
&lt;br /&gt;
	pthread_attr_init(&amp;amp;atributo_de_thread);&lt;br /&gt;
	pthread_attr_setdetachstate(&lt;br /&gt;
		&amp;amp;atributo_de_thread, PTHREAD_CREATE_JOINABLE);&lt;br /&gt;
&lt;br /&gt;
	pthread_mutex_init(&amp;amp;mutex_de_x,NULL);&lt;br /&gt;
	pthread_mutex_init(&amp;amp;mutex_de_y,NULL);&lt;br /&gt;
	&lt;br /&gt;
	if (pthread_create(&amp;amp;thread1,&lt;br /&gt;
		&amp;amp;atributo_de_thread,&lt;br /&gt;
		minha_thread1,NULL))&lt;br /&gt;
		printf(&amp;quot;Erro ao criar a minha_thread1.\n&amp;quot;);&lt;br /&gt;
&lt;br /&gt;
	if (pthread_create(&amp;amp;thread2,&lt;br /&gt;
		&amp;amp;atributo_de_thread,minha_thread2,NULL))&lt;br /&gt;
		printf(&amp;quot;Erro ao criar a minha_thread2.\n&amp;quot;);&lt;br /&gt;
&lt;br /&gt;
	if (pthread_join(thread1,(void **)&amp;amp;retorno_da_thread))&lt;br /&gt;
		printf(&amp;quot;Erro no join de minha_thread1.\n&amp;quot;);&lt;br /&gt;
	else&lt;br /&gt;
		printf(&amp;quot;minha_thread1 joined.\n&amp;quot;);&lt;br /&gt;
&lt;br /&gt;
	if (pthread_join(thread2,(void **)&amp;amp;retorno_da_thread))&lt;br /&gt;
		printf(&amp;quot;Erro no join de minha_thread2.\n&amp;quot;);&lt;br /&gt;
	else&lt;br /&gt;
		printf(&amp;quot;minha_thread2 joined.\n&amp;quot;);&lt;br /&gt;
		&lt;br /&gt;
	pthread_mutex_destroy(&amp;amp;mutex_de_y);&lt;br /&gt;
	pthread_mutex_destroy(&amp;amp;mutex_de_x);&lt;br /&gt;
&lt;br /&gt;
	pthread_attr_destroy(&amp;amp;atributo_de_thread);&lt;br /&gt;
&lt;br /&gt;
	pthread_exit(NULL);&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;/div&gt;</summary>
		<author><name>Adonaimedrado</name></author>	</entry>

	</feed>