Skip to content

ARC: variables are no copied on the thread spawn causing crashes #13708

@cooldome

Description

@cooldome

The test case that works in single threaded mode, but not in multithreaded mode.
Compile with --gc:arc --threads:on

import threadpool
import strutils
import os

proc work(s: string) =
  let (abs_dir, file_ext) = splitPath(s)
  echo file_ext # needed to make task heavier to produce race conditions
  doAssert(file_ext.endsWith(".xml"))

proc thread_run(p: string, singleThread = false) =
  let path = p
  if singleThread:
    work(path)
  else:
    spawn(work(path))

var i = 0
for path in walkDirRec(r"c:\"):
  if splitFile(path).ext == ".xml":
    echo path
    thread_run(path, singleThread = false) # works  if singleThread = true
    i.inc
  if i >= 1000:
    break

sync()

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions