spdegabrielle
2020-9-24 10:22:03

New racket stickers for the laptop


spdegabrielle
2020-9-24 10:22:12

spdegabrielle
2020-9-24 10:22:43

Quickscript competition 2020 and small racket logo


laurent.orseau
2020-9-24 11:57:27

You’ll soon need a new laptop to put more stickers!


spdegabrielle
2020-9-24 12:29:21

I will!


dynapate
2020-9-24 13:59:33

@dynapate has joined the channel


gknauth
2020-9-24 15:39:59

enyala9733
2020-9-24 16:30:08

hello I have a silly question ..


enyala9733
2020-9-24 16:30:17

I have read this >A thread cell can be preserved; when a new thread is created, the creating thread’s value for a preserved thread cell serves as the initial value for the cell in the created thread. For a non-preserved thread cell, a new thread sees the same initial value (specified when the thread cell is created) as all other threads. my question is ,what the “thread cell” is? and what this mean “the creating thread’s value for a preserved thread cell serves as the initial value for the cell in the created thread”,can someone write some code to explain it,thanks


soegaard2
2020-9-24 16:38:37

@enyala9733 A thread (process) A running a program P can start another thread B running the same program. For a standard variable x whose value is stored in some location (memory cell) the location is shared between the two threads. If process B writes a value to x, then thread A can see the value, when x is referenced.

A thread cell also contains a value that can be referenced and stored to. But when the thread B is created, all thread cells of A is copied to create a new set of thread cells for B. The initial values will the whatever was stored in the thread cells of A.

Now when a the thread B stores a new value into a thread cell, only the B can se the change.

That is: standard variables are shared between threads and thread cells are not.


soegaard2
2020-9-24 16:41:00

Now the story above holds for preserved thread cells.


soegaard2
2020-9-24 16:41:35

I.e. when a new thread is created the current value of the thread cell is used.


soegaard2
2020-9-24 16:42:24

In the case of a non-preserved thread cell, the current value isn’t copied - but the original value supplied when the thread cell was created is used.


soegaard2
2020-9-24 16:42:55

I’ll try to write an example.


enyala9733
2020-9-24 16:44:38

thanks for reply ,wha’s the different between thread cell and c++’s <https://docs.microsoft.com/en-us/cpp/parallel/thread-local-storage-tls|Thread Local Storage>?


soegaard2
2020-9-24 16:46:17

This program: #lang racket (define cell (make-thread-cell 'original #t)) (thread-cell-set! cell 'A) (void (displayln (list 'A (thread-cell-ref cell))) (thread (λ() (displayln (list 'B (thread-cell-ref cell)))))) prints (A A) (B A)


massung
2020-9-24 16:46:19

maybe this will help: (define p (make-parameter #f)) (define (test) (parameterize ([p 'alt-thread]) (thread (λ () (displayln (p)))) (p 'main-thread) (displayln (p)))) (test)


massung
2020-9-24 16:46:38

lol - same idea :slightly_smiling_face:


soegaard2
2020-9-24 16:46:49

And this program: #lang racket (define cell (make-thread-cell 'original #f)) (thread-cell-set! cell 'A) (void (displayln (list 'A (thread-cell-ref cell))) (thread (λ() (displayln (list 'B (thread-cell-ref cell)))))) prints: (A A) (B original)


massung
2020-9-24 16:47:34

If you’ve used Common Lisp, it’s more akin to a dynamically scoped variable than thread local. Dynamically scoped variables are thread local, but the value it has when the thread is spawned is passed as the initial value to the thread as well


soegaard2
2020-9-24 16:48:16

I’ll admit ignorance wrt C++.


enyala9733
2020-9-24 16:51:40

in “non-preserved”,what’s the “original value supplied”


soegaard2
2020-9-24 16:52:31

See the example below. In the example the original value is ’orignal but it can be anything you like.


soegaard2
2020-9-24 16:53:12

(below in the main thread)


enyala9733
2020-9-24 16:55:08

Hahaha, yes, I have seen it, no need to explain


enyala9733
2020-9-24 16:56:13

Thank you for your sample code, I found it by searching (make-thread-cell) https://docs.racket-lang.org/reference/threadcells.html Now i know what’s going on


willbanders
2020-9-24 18:36:26

the apple logo shining through the racket sticker looks super cool


plragde
2020-9-25 01:15:28

A case where ignorance really is bliss