[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

bug#38807: [Feature request]: Support lisp workers like web workers.

From: HaiJun Zhang
Subject: bug#38807: [Feature request]: Support lisp workers like web workers.
Date: Sat, 4 Jan 2020 14:41:58 +0800

Workers don’t have to be in dedicated native threads. It is decided by the lisp machine if they are run in a lisp machine.

在 2020年1月3日 +0800 PM10:11,arthur miller <address@hidden>,写道:
As a concept, I am not sure a thread is the best solution to implement for a high level scripting runtime as Emacs lisp. Thread is a relatively primitive concept and leaves a lot to  applications programmer to decide and manage. In concurrent programming a thread is OK-ish concept, but it might not be the best for truly parallel problem solving.

Creating more threads than there are physical cpus creates overhead that might eat up benefits of parallelism. It  also forces a programmer to think in terms of machine, scheduling, synchronization etc. It can be more effective and more lisp-ish to think in terms of tasks and let the core manage the threads and scheduling on it's own.

Tasks let us think about the work we wish to perform and not how to perform it. It lets runtime create number of worker threads and schedule them automatically instead of forcing programmers to join, synchronize etc

As a concept a web worker is just a worker thread introduced as idea in various single threaded gui toolkits long ago. Java's Swing popularized worker threads heavily back in days, and I don't remember if MFC also made a deal of those before Swing or after.

Anyway, these were just ordinary threads,  doing some work, like populating big lists and similar, nothing special. However back in days threads were cheap. Everything run on one CPU, and threaded programming was mostly what we today call concurrent programming. 

Since Swing and Mfc were big things, we have got multi core CPUs as mainstream and threads have got much more expensive to create and communicate with. Java threads back at days where super cheap to create. I am not sure how expensive are posix threads on different cpus, but I know that win32 threads are quite expensive/slow. For a small work it might be more expensive to process it in separate thread. 

Tasks can be mapped on entire thread or put into a queue for physical threads to pick them up. Thus I think tasks might be more suited for say an input queue or render queue and similar. 

If I remember well, certain version of DirectX used to process input in separate thread, which they abandoned in some later version. However I stopped to work with dx years ago, before dx10 come out, so I don't know how they do nowadays. 

Skickat från min Samsung Galaxy-smartphone.

-------- Originalmeddelande --------
Från: HaiJun Zhang <address@hidden>
Datum: 2020-01-03 04:36 (GMT+01:00)
Till: Eli Zaretskii <address@hidden>
Kopia: address@hidden, address@hidden
Ämne: bug#38807: [Feature request]: Support lisp workers like web workers.

在 2020年1月2日 +0800 AM12:21,Eli Zaretskii <address@hidden>,写道:

Then these threads cannot really run Lisp at all, nor even directly
affect Lisp data. So in effect you want to be able to run threads
that don't enter the Lisp interpreter, nor modify any Lisp data.  

For web worker, they have different contexts. The following is from MDN(https://developer.mozilla.org/en-US/docs/Web/API/Web_Workers_API/Using_web_workers):

workers run in another global context that is different from the current window. Thus, using the windowshortcut to get the current global scope (instead of self) within a Worker will return an error.

The worker context is represented by a DedicatedWorkerGlobalScope object in the case of dedicated workers (standard workers that are utilized by a single script; shared workers use SharedWorkerGlobalScope). A dedicated worker is only accessible from the script that first spawned it, whereas shared workers can be accessed from multiple scripts.

reply via email to

[Prev in Thread] Current Thread [Next in Thread]