Skip to content

Instantly share code, notes, and snippets.

@justinfx
Created January 9, 2016 06:45
Show Gist options
  • Save justinfx/ab9fa42b0df19dc2c1f6 to your computer and use it in GitHub Desktop.
Save justinfx/ab9fa42b0df19dc2c1f6 to your computer and use it in GitHub Desktop.
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()
// 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