This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import javax.ws.rs.core.Context; | |
import javax.ws.rs.Path; | |
import javax.ws.rs.GET; | |
import com.sun.jersey.api.view.Viewable; | |
@GET | |
@Path("/index") | |
public Viewable index( | |
@Context HttpServletRequest request, | |
@Context HttpServletResponse response) throws Exception |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import javax.ws.rs.core.Context; | |
import javax.ws.rs.Path; | |
import javax.ws.rs.GET; | |
import com.sun.jersey.api.view.Viewable; | |
@GET | |
@Path("/index") | |
public Viewable index( | |
@Context HttpServletRequest request, |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class Main{ | |
public static void main(String[] argv){ | |
System.out.println("heard : \u2665 \u2661"); | |
System.out.println("club : \u2663 \u2667"); | |
System.out.println("diamond: \u2666 \u2662"); | |
System.out.println("spade : \u2660 \u2664"); | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class Main{ | |
public static void main(String[] argv){ | |
System.out.println("club : \u2663 \u2667"); | |
System.out.println("heard : \u2665 \u2661"); | |
System.out.println("diamond: \u2666 \u2662"); | |
System.out.println("spade : \u2660 \u2664"); | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
heard :♥ ♡ | |
club :♣ ♧ | |
diamond:♦ ♢ | |
spade :♠ ♤ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
#include <stdio.h> | |
using namespace std; | |
const char BLACK_CLUB_SUIT[] = "\xe2\x99\xa3"; // \u2663 | |
const char BLACK_HEART_SUIT[] = "\xe2\x99\xa5"; // \u2665 | |
const char BLACK_DIAMOND_SUIT[] = "\xe2\x99\xa6"; // \u2666 | |
const char BLACK_SPADE_SUIT[] = "\xe2\x99\xa0"; // \u2660 | |
const char WHITE_HEART_SUIT[] = "\xe2\x99\xa1"; // \u2661 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
... | |
pthread_mutex_lock(&lock1); | |
if(pthread_mutex_trylock(&lock2)){ | |
pthread_mutex_unlock(&lock1); | |
}else{ | |
count++; | |
pthread_mutex_unlock(&lock2); | |
} | |
pthread_mutex_unlock(&lock1); | |
... |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
... | |
pthread_mutex_lock(&lock1); | |
while ( pthread_mutex_trylock(&lock2) ){ | |
// Free resource to avoid deadlock | |
pthread_mutex_unlock(&lock1); | |
... | |
pthread_mutex_lock(&lock1); | |
} | |
count++; | |
pthread_mutex_unlock(&lock1); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
void* thread1_function(void* parameter){ | |
pthread_mutex_lock(&lock1); | |
pthread_mutex_lock(&lock2); // DEADLOCK | |
... | |
... | |
pthread_mutex_lock(&lock2); | |
pthread_mutex_lock(&lock1); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
./main | |
thread 2: 1 | |
thread 1: 2 | |
thread 2: 3 | |
thread 1: 4 | |
thread 2: 5 | |
thread 1: 6 | |
thread 2: 7 | |
thread 1: 8 | |
thread 2: 9 |