5 Dec 2023 |
Elegantbeef | {.cast(gcSafe).}:
queue.addLast(myStr)
| 01:16:35 |
guttural666 | 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 |
bostonboston | is it still recommended to use the {.guard: .} pragma and withLock template | 01:18:33 |
Elegantbeef | Yes | 01:18:39 |
Elegantbeef | Though I'd say a ptr (Deque[string, Lock) makes more sense than a global variable | 01:19:13 |
Elegantbeef | Although I have no clue if deques explode when shared across thread | 01:19:25 |
guttural666 | * 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 |
bostonboston | so something like this
type
Scheduler = object
var
lock {.global.}: Lock
queue_thr: Thread[Scheduler]
queue {.global, guard: lock.}: Deque[string] = initDeque[string]()
initLock lock
proc sch_thread(sch: Scheduler) {.thread.} =
{.cast(gcsafe).}:
withLock lock:
let str = "last"
queue.addLast(str)
proc main =
var sch: Scheduler
createThread(queue_thr, sch_thread, sch)
joinThread(queue_thr)
withLock lock:
echo queue
main() | 01:19:27 |
Elegantbeef | Isn't that global pragma redundant | 01:19:50 |
Elegantbeef | It's not marked {.threadVar.} | 01:20:01 |
bostonboston | probably, I copied it from another codebase of mine thats probably wrong | 01:20:24 |
Elegantbeef | Global is for making variables inside of a procedure global | 01:20:39 |
bostonboston | I knew it did that, suppose I thought it did more | 01:21:01 |
guttural666 | thanks, going to investigate that | 01:22:02 |
bostonboston | {.threadVar.} makes a copy not a reference yeah? | 01:22:19 |
Elegantbeef | It makes each thread have it's own variable | 01:23:23 |
Elegantbeef | So it's thread local | 01:23:27 |
Elegantbeef | Without it it's global | 01:23:31 |
bostonboston | ah | 01:23:58 |
bostonboston | what is owned used for, not many docs on it | 03:10:24 |
Elegantbeef | It's a deprecated idea that was meant to indicate ownership | 03:13:06 |
Elegantbeef | move semantics and isolated I think mostly replaced it | 03:13:15 |
stoneface86 | was wondering what that was, std/streams still uses it | 03:14:36 |
bostonboston | how do lent and sink fit in to that | 03:17:59 |
bostonboston | if at all | 03:18:06 |
Elegantbeef | Well owned was the first pass at ARC really inside of the "newRuntime" | 03:20:36 |
Elegantbeef | https://github.com/nim-lang/RFCs/issues/144 | 03:20:56 |
Elegantbeef | Owned has turned into isolated afaik | 03:21:17 |
Elegantbeef | Atleast in some part | 03:21:21 |
Elegantbeef | 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 |