Skip to content

Commit

Permalink
fix: Update
Browse files Browse the repository at this point in the history
  • Loading branch information
sirateek committed Apr 6, 2024
1 parent eaec0a9 commit f996d72
Showing 1 changed file with 35 additions and 4 deletions.
39 changes: 35 additions & 4 deletions main.go
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
package main

import (
"context"
"encoding/json"
"fmt"
containerlib "github.com/resource-aware-jds/container-lib"
"github.com/resource-aware-jds/container-lib/model"
"github.com/resource-aware-jds/container-lib/pkg/containerlibcontext"
"github.com/sirupsen/logrus"
"os"
"os/signal"
"syscall"
"time"
)

Expand Down Expand Up @@ -34,10 +38,37 @@ func main() {
unmarshalledData.MemoryAllocationSize = &size
}

fakeAllocation := make([]byte, *unmarshalledData.MemoryAllocationSize)
for i := 0; i < *unmarshalledData.MemoryAllocationSize; i++ {
fakeAllocation[i] = 0x99
}
innerCtx := context.Background()
newCtx, cancelFunc := context.WithCancel(innerCtx)
a := make([]byte, (*unmarshalledData.MemoryAllocationSize)*1000000)
fmt.Println("Reserved: ", " : ", *unmarshalledData.MemoryAllocationSize, "mb")
fmt.Println("Press Ctrl+C to abort this operation")
go func(innerCtx context.Context) {
for {
select {
case <-ctx.Done():
fmt.Println("Done.")
return
default:
for i := range a {
a[i] = 0x99
}
}
fmt.Println("Sleep 10 Second before reserving the next")
time.Sleep(10 * time.Second)
}

}(newCtx)

// Gracefully Shutdown
// Make channel listen for signals from OS
gracefulStop := make(chan os.Signal, 1)
signal.Notify(gracefulStop, syscall.SIGTERM)
signal.Notify(gracefulStop, syscall.SIGINT)

<-gracefulStop

cancelFunc()

time.Sleep(sleepTime)
fmt.Println(unmarshalledData)
Expand Down

0 comments on commit f996d72

Please sign in to comment.