Nim programming language

6953 Members
Official Matrix channel for the Nim programming language. This channel is bridged with our main Discord and Gitter channels.85 Servers

Load older messages

5 Dec 2023
@_discord_375727321958580228:t2bot.ioguttural666 if I have a queue and somebody has to write to it and the scheduler has to read from it, that is my problem rn 01:18:24
@_discord_212649973215526912:t2bot.iobostonboston is it still recommended to use the {.guard: .} pragma and withLock template 01:18:33
@elegantbeef:matrix.orgElegantbeef Though I'd say a ptr (Deque[string, Lock) makes more sense than a global variable 01:19:13
@elegantbeef:matrix.orgElegantbeefAlthough I have no clue if deques explode when shared across thread01:19:25
@_discord_375727321958580228:t2bot.ioguttural666 * if I have a queue and somebody has to write to it and the scheduler has to read from it (and pop the queue), that is my problem rn 01:19:27
@_discord_212649973215526912:t2bot.iobostonboston so something like this
  Scheduler = object 

  lock {.global.}: Lock
  queue_thr: Thread[Scheduler]
  queue {.global, guard: lock.}: Deque[string] = initDeque[string]()

initLock lock 

proc sch_thread(sch: Scheduler) {.thread.} = 
    withLock lock:
      let str = "last"

proc main =
  var sch: Scheduler
  createThread(queue_thr, sch_thread, sch)
  withLock lock:
    echo queue

@elegantbeef:matrix.orgElegantbeefIsn't that global pragma redundant01:19:50
@elegantbeef:matrix.orgElegantbeef It's not marked {.threadVar.} 01:20:01
@_discord_212649973215526912:t2bot.iobostonboston probably, I copied it from another codebase of mine thats probably wrong 01:20:24
@elegantbeef:matrix.orgElegantbeefGlobal is for making variables inside of a procedure global01:20:39
@_discord_212649973215526912:t2bot.iobostonboston I knew it did that, suppose I thought it did more 01:21:01
@_discord_375727321958580228:t2bot.ioguttural666 thanks, going to investigate that 01:22:02
@_discord_212649973215526912:t2bot.iobostonboston {.threadVar.} makes a copy not a reference yeah? 01:22:19
@elegantbeef:matrix.orgElegantbeefIt makes each thread have it's own variable01:23:23
@elegantbeef:matrix.orgElegantbeefSo it's thread local01:23:27
@elegantbeef:matrix.orgElegantbeefWithout it it's global01:23:31
@_discord_212649973215526912:t2bot.iobostonboston ah 01:23:58
@_discord_212649973215526912:t2bot.iobostonboston what is owned used for, not many docs on it 03:10:24
@elegantbeef:matrix.orgElegantbeefIt's a deprecated idea that was meant to indicate ownership03:13:06
@elegantbeef:matrix.orgElegantbeef move semantics and isolated I think mostly replaced it 03:13:15
@_discord_228590216808628235:t2bot.iostoneface86 was wondering what that was, std/streams still uses it 03:14:36
@_discord_212649973215526912:t2bot.iobostonboston how do lent and sink fit in to that 03:17:59
@_discord_212649973215526912:t2bot.iobostonboston if at all 03:18:06
@elegantbeef:matrix.orgElegantbeef Well owned was the first pass at ARC really inside of the "newRuntime" 03:20:36
@elegantbeef:matrix.orgElegantbeefOwned has turned into isolated afaik03:21:17
@elegantbeef:matrix.orgElegantbeefAtleast in some part03:21:21
@elegantbeef:matrix.orgElegantbeef Actually that's not really true cause owned was meant to allow you to share resources across threads but only have one side actually own it 03:23:24

There are no newer messages yet.

Back to Room ListRoom Version: