Wikipedia:Reference desk/Archives/Computing/2012 October 30#thread execution in java
{{#ifeq:{{PAGENAME}}|Special:Undelete| |{{#if:|
python
need small python script to do global find and replace with a plain text file. 70.114.254.43 (talk) 02:58, 30 October 2012 (UTC)
:Consult the [http://docs.python.org/3/library/re.html Python Manual, §6.2, Regular expression operations]. The [http://docs.python.org/3/library/re.html#re.sub re.sub()] function can find and replace strings. Nimur (talk) 04:19, 30 October 2012 (UTC)
thread execution in java
i know that due to multithreading cpu idle time is reduced.
when cpu is free or waiting for input or output then it starts execution of another thread.
I am expressing my doubts based on below programme.
{{hidden begin|title=Source Code|titlestyle = background:palegreen; text-align:center;}}
class thread6
{
public static void main(String args[])
{
Thread count1=new Thread(new CountDownEven());
Thread t=Thread.currentThread();
count1.start();
for(int i=11;i<=20;i=i+2)
{
System.out.println(t.getName()+"----"+i);
}
}
}
class CountDownEven implements Runnable
{
public void run()
{
Thread t=Thread.currentThread();
for(int i=0;i<10;i=i+2)
{
System.out.println(t.getName()+"----"+i);
}
}
}
{{hidden end}}
my doubts:
- why the above programme gives different outputs.?
- Execution starts from main thread. in main thread i have written for loop.Before that i wrote count1.start,which starts execution of another thread.but some times for loop in main thread gets executed before another thread.why ?how can i understand this ?
- when control moves from one thread to another thread?
- can you tell me execution of threads and behaviour of thread scheduler? or can you give some website details?
{{hidden begin|title=Output|titlestyle = background:palegreen; text-align:center;}}
outputs of above programme:
out put1
------------:
Thread-0----0
main----11
Thread-0----2
Thread-0----4
Thread-0----6
main----13
main----15
main----17
main----19
Thread-0----8
output2
------------
Thread-0----0
Thread-0----2
Thread-0----4
main----11
main----13
main----15
Thread-0----6
Thread-0----8
main----17
main----19
output3:
---------------
main----11
Thread-0----0
Thread-0----2
main----13
main----15
main----17
main----19
Thread-0----4
Thread-0----6
Thread-0----8
{{hidden end}}
— Preceding unsigned comment added by Phanihup (talk • contribs) 05:48, 30 October 2012 (UTC)
:The scheduler of the OS (or of the Java VM, if that does not use the OS scheduler) decides which thread to run based on a number of factors, which potentially include I/O events, system load, and even the (virtual) toss of a coin. In your case, one simple explanation might be that your computer has multiple cores (most nowadays have), and that the systems schedules some threads immediately if there are idle cores, but lets the main threat running for a bit if they are otherwise occupied, e.g. with displaying sand clocks or morphing windows into the dock, or checking if the mouse hovers near a tool tip, or any other of the million things a modern OS does at any one time. --Stephan Schulz (talk) 07:52, 30 October 2012 (UTC)
spreadsheet link/synchronize sheets
I want the several sheets in a spreadsheet to be multiple "views" into the same data.
If I insert or delete a row in one sheet, I want it to be simultaneously inserted/deleted across all sheets.
Is there any way to do that?
Thanks. — Preceding unsigned comment added by 141.154.221.145 (talk) 09:30, 30 October 2012 (UTC)
Help with ASCII art in C
I am completing [http://www.cs.ucsb.edu/~pconrad/cs16/10W/labs/lab03/ this lab] for a class. I have reached the point where I need to code the T out of asterisks.
My code is as follows:
- include
- include
void starL(int width, int height)
{
int i;
// check if parameters are valid
if ((width<2) || (height < 2) || (width%2==0))
return; // return without printing anything
// print width stars, followed by a final \n
for (i=0; i printf("*"); // print height-1 rows of *\n for (i=0; i printf("*\n"); printf("\n"); return; // we are finished } The problem is, when I attempt to generate a 3x3 T, I get: I somehow need to make the "width" line go above the "height" line, and then have the height line spaced (width/2) columns over. How would I do that? 169.231.8.73 (talk) 11:54, 30 October 2012 (UTC) :It looks like your width line is above the height line, you just need to output a "\n" after you are done drawing the width line. For moving things over, you'll need to add width/2 spaces in front of each piece of the height line. You can place for loops inside of each other, just give the inner one a new variable such as j. I don't want to just give you a solution, but play around with that idea and let us know if you have trouble. (Just edited after realizing I said height instead of width once)209.131.76.183 (talk) 12:17, 30 October 2012 (UTC) ::I've formatted the question for easier reading. Nimur (talk) 15:03, 30 October 2012 (UTC) :I strongly suggest you manually step through the code, and print asterisks on a piece of paper (or in a text file), to see what your code is doing. StuRat (talk) 16:41, 30 October 2012 (UTC)
PCIe x1, x4 & x8 Cards' MD1 & MD2 Form Factors
Are the specifications/dimensions of the MD1 and MD2 form factors for PCIe x1, x4 & x8 cards available anywhere online for free? My computer accepts regular cards, but I'm just curious to learn more about these exotic enterprisey form factors. — Preceding unsigned comment added by 49.245.15.32 (talk) 13:24, 30 October 2012 (UTC)
:It looks like this is the spec update introducing the change: [http://www.pcisig.com/specifications/conventional/conventional_pci/lowp_ecn.pdf] 209.131.76.183 (talk) 13:33, 30 October 2012 (UTC)