Prev: Tue Feb 23 Seminar - Ada and SPARK for education and research
Next: Catching Standard_Error with GNAT.Expect
From: Hibou57 (Yannick Duchêne) on 7 Feb 2010 14:24 As it is the subject here : I've just checked at least with GNAT it work nice to create a task, invok a CreateProcess from this Ada task and then WaitForSingleObject with delay INFINITE on the process handle always in the same Ada task : other Ada task are still running normally (a protected object can then be used to tell any other task the process has terminated). I was wondering about the cost of threads on Windows, as GNAT create Ada task as Windows thread (I suppose its the same for Janus and others, I hope to be honest). I just found there is a default allocated stack of 1M bytes, and nothing about the cost of task creation and task switch in CPU cycles (from a pure point of view, dropping any page fault and the like). If someone know a good source about it, it would be nice (this is to weigh up the choice to have an Ada task per process vs. a single Ada task managing multiple processes). The sole words about it in the MS reference says : > The number of threads a process can create is limited by the > available virtual memory. By default, every thread has one megabyte > of stack space. Therefore, you can create at most 2028 threads. If > you reduce the default stack size, you can create more threads. > However, your application will have better performance if you create > one thread per processor and build queues of requests for which the > application maintains the context information. A thread would > process all requests in a queue before processing requests in the > next queue. While the thread (then Ada task) stack size can be tuned with the Storage_Size attribute, while formally speaking, as of [ARM 13.1(60)], this is not strictly the stack size, but rather a size including the stack size. And this attribute is marked as obsolescent in [ARM J.6], in favor of the pragma which as the same name.
From: Hibou57 (Yannick Duchêne) on 7 Feb 2010 14:36 On 7 fév, 20:24, Hibou57 (Yannick Duchêne) <yannick_duch...(a)yahoo.fr> wrote: > stack size. And this attribute is marked as obsolescent in [ARM J.6], > in favor of the pragma which as the same name. Oops : this is obviously Annexe J.9 (not J.6)
From: Hibou57 (Yannick Duchêne) on 7 Feb 2010 15:35 On 7 fév, 20:24, Hibou57 (Yannick Duchêne) <yannick_duch...(a)yahoo.fr> wrote: > I was wondering about the cost of threads on Windows, as GNAT create > Ada task as Windows thread (I suppose its the same for Janus and > others, I hope to be honest). > [...] > > The sole words about it in the MS reference says : For any interested parties, I've found an answer which seems reasonable here : http://stackoverflow.com/questions/304752/how-to-estimate-the-thread-context-switching-overhead Two interesting quotes are: > Oh, and I remember an application running on Windows CE 4.X, where > we also have four threads with intensive switching at times, and > never ran into performance issues. and > Output > Number of thread switches in about one second was 108406 > Over 100'000 is not too bad and that even though we have locking and > conditional waits. I'd guess without all this stuff at least twice > as many thread switches were possible a second. Threads does not cost so much after all (keep in mind this was on architecture with support for Windows, this is Windows specific).
From: Dmitry A. Kazakov on 7 Feb 2010 16:36 On Sun, 7 Feb 2010 11:24:41 -0800 (PST), Hibou57 (Yannick Duch�ne) wrote: > As it is the subject here : I've just checked at least with GNAT it > work nice to create a task, invok a CreateProcess from this Ada task > and then WaitForSingleObject with delay INFINITE on the process handle > always in the same Ada task : other Ada task are still running > normally (a protected object can then be used to tell any other task > the process has terminated). You can use WaitForSingleObject in order to determine if the object (like the process) is signaled without waiting. (Do not forget to close the object handle when you don't need it.) > I was wondering about the cost of threads on Windows, as GNAT create > Ada task as Windows thread (I suppose its the same for Janus and > others, I hope to be honest). I just found there is a default > allocated stack of 1M bytes, and nothing about the cost of task > creation and task switch in CPU cycles (from a pure point of view, The cost of switching depends on the processor. I remember that it was very high for x86 in earlier times. I cannot tell if it is still so. But I think you can measure it. Start several tasks incrementing a counter in a loop. A Windows call Delay (0) should switch the task prematurely. Do that each, say 100_000 increments (it must be shorter than 1ms, otherwise Windows scheduler will intervene). Run this until the sum of counters reaches some value. Do the same with one task. The time difference divided by the number of switches is the task switching overhead. > dropping any page fault and the like). If someone know a good source > about it, it would be nice (this is to weigh up the choice to have an > Ada task per process vs. a single Ada task managing multiple > processes). The latter will not work in most cases because of blocking I/O. Well, there is overlapped I/O API under Windows, but you would need to rewrite all code for this, and not all (a minority in fact) devices support overlapped I/O. -- Regards, Dmitry A. Kazakov http://www.dmitry-kazakov.de
First
|
Prev
|
Pages: 1 2 Prev: Tue Feb 23 Seminar - Ada and SPARK for education and research Next: Catching Standard_Error with GNAT.Expect |