Created
September 22, 2012 05:55
-
-
Save samuelkadolph/3765289 to your computer and use it in GitHub Desktop.
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 <pthread.h> | |
#include <stdio.h> | |
static pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER; | |
static pthread_cond_t cond = PTHREAD_COND_INITIALIZER; | |
extern void __wait() { | |
printf("__wait pthread_mutex_lock # => %d\n", pthread_mutex_lock(&mutex)); | |
printf("__wait pthread_cond_wait # => %d\n", pthread_cond_wait(&cond, &mutex)); | |
printf("__wait pthread_mutex_unlock # => %d\n", pthread_mutex_unlock(&mutex)); | |
} | |
extern void __signal() { | |
printf("__signal pthread_mutex_lock # => %d\n", pthread_mutex_lock(&mutex)); | |
printf("__signal pthread_cond_broadcast # => %d\n", pthread_cond_broadcast(&cond)); | |
printf("__signal pthread_mutex_unlock # => %d\n", pthread_mutex_unlock(&mutex)); | |
} |
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
package main | |
import ( | |
"log" | |
"time" | |
) | |
func __wait () __asm__("__wait") | |
func __signal () __asm__("__signal") | |
func main() { | |
quit := make(chan int) | |
go func() { | |
runtime.LockOSThread() | |
log.Printf("before wait") | |
__wait() | |
log.Printf("after wait") | |
quit <- 1 | |
}() | |
time.Sleep(time.Second) | |
log.Printf("before signal") | |
__signal() | |
log.Printf("after signal") | |
<-quit | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment