Created
January 9, 2016 06:45
-
-
Save justinfx/ab9fa42b0df19dc2c1f6 to your computer and use it in GitHub Desktop.
This file contains 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
from flask.ext.restful import Resource | |
from flask import Response | |
from ctypes import CDLL | |
gotest = CDLL("gotest.so") | |
class api2(Resource): | |
def get(self): | |
return gotest.GetValWithConcurrency() | |
This file contains 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
// gotest | |
package main | |
import ( | |
"fmt" | |
"sync" | |
) | |
import "C" | |
//export GetValWithConcurrency | |
func GetValWithConcurrency() int { | |
fmt.Println("Called GetValWithConcurrency") | |
someResults := make(chan int) | |
var producer sync.WaitGroup | |
var consumer sync.WaitGroup | |
var makeResults = func(result chan int) { | |
defer producer.Done() | |
result <- 1 | |
} | |
for i := 0; i < 100; i++ { | |
producer.Add(1) | |
go makeResults(someResults) | |
} | |
consumer.Add(1) | |
var total int | |
go func() { | |
defer consumer.Done() | |
for result := range someResults { | |
total += result | |
} | |
}() | |
producer.Wait() | |
close(someResults) | |
consumer.Wait() | |
return total | |
} | |
func main() { | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment