Answers for "what is multithreading"

18

multithreading

//Bless anyone who decides to follow this path
Posted by: Guest on February-18-2020
4

how to do multithreading

import threading

def func1():
	# your function
def func2():
	# your function
if __name__ == '__main__':
	threading.Thread(target=func1).start()
	threading.Thread(target=func2).start()
Posted by: Guest on July-30-2021
1

what is multithreading

Multithreading is a model of program execution 
that allows for multiple threads to be created 
within a process, executing independently but 
concurrently sharing process resources. 
Depending on the hardware, threads can run 
fully parallel if they are distributed to their own CPU core.
Posted by: Guest on August-06-2021
1

multithreading

#!/usr/bin/python

import thread
import time

# Define a function for the thread
def print_time( threadName, delay):
   count = 0
   while count < 5:
      time.sleep(delay)
      count += 1
      print "%s: %s" % ( threadName, time.ctime(time.time()) )

# Create two threads as follows
try:
   thread.start_new_thread( print_time, ("Thread-1", 2, ) )
   thread.start_new_thread( print_time, ("Thread-2", 4, ) )
except:
   print "Error: unable to start thread"

while 1:
   pass
Posted by: Guest on July-15-2020
2

multithreading in java

class Count implements Runnable
{
   Thread mythread ;
   Count()
   { 
      mythread = new Thread(this, "my runnable thread");
      System.out.println("my thread created" + mythread);
      mythread.start();
   }
   public void run()
   {
      try
      {
        for (int i=0 ;i<10;i++)
        {
          System.out.println("Printing the count " + i);
          Thread.sleep(1000);
        }
     }
     catch(InterruptedException e)
     {
        System.out.println("my thread interrupted");
     }
     System.out.println("mythread run is over" );
   }
}
class RunnableExample
{
    public static void main(String args[])
    {
       Count cnt = new Count();
       try
       {
          while(cnt.mythread.isAlive())
          {
            System.out.println("Main thread will be alive till the child thread is live"); 
            Thread.sleep(1500);
          }
       }
       catch(InterruptedException e)
       {
          System.out.println("Main thread interrupted");
       }
       System.out.println("Main thread run is over" );
    }
}
Posted by: Guest on November-07-2020
0

multithreading in java simple example

class MultithreadingDemo extends Thread{  
  public void run(){  
    System.out.println("My thread is in running state.");  
  }   
  public static void main(String args[]){  
     MultithreadingDemo obj=new MultithreadingDemo();   
     obj.start();  
  }  
}
Posted by: Guest on October-06-2020

Browse Popular Code Answers by Language