Skip to content

Conversation

ringabout
Copy link
Member

@ringabout ringabout commented Nov 14, 2021

IMHO, ORC uses shared heap and should clean the cycle before threads exit.

A leak, for example

import os

type
  WorkRequest = ref object
    id: WorkRequest
    data: string
    time: array[100000, int]

var
  thread: Thread[void]


proc workThread() {.thread.} =
  var x = WorkRequest()
  x.id = x

while true:
  createThread(thread, workThread)
  sleep(1000)

@ringabout
Copy link
Member Author

Consider a circle in a thread;

import os

type
  WorkRequest = ref object
    id: WorkRequest

var
  thread: Thread[void]

proc workThread() {.thread.} =
  var x = WorkRequest()
  x.id = x

createThread(thread, workThread)
sleep(1000)

I need a solution to collect this circle. I can think of two solutions

proc workThread() {.thread.} =
  block:
    var x = WorkRequest()
    x.id = x
  GC_runOrc()
proc workThread() {.thread.} =
  defer: GC_runOrc()
  var x = WorkRequest()
  x.id = x

Are there some solutions preferred?

@ringabout ringabout changed the title test orc execute GC_runOrc before exit threads Nov 14, 2021
@ringabout ringabout changed the title execute GC_runOrc before exit threads execute GC_runOrc before exiting threads Nov 14, 2021
@Araq
Copy link
Member

Araq commented Nov 14, 2021

GC_runOrc is a blunt tool and we have to watch out not to call it too often, the performance depends on the client application.

@ringabout
Copy link
Member Author

make sense

@ringabout ringabout closed this Mar 9, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants