Back to: Operating System
0
Practical 2 (A)
Write a program to work with a single thread.
Algorithm:
Steps:
1. Start.
2. Initialize or write the method.
3. Initialize a thread.
4. Assign method on the thread.
5. Run thread.
6. End.
Code:
public class SingleThread{
public static void main(String args[]){
for (int i = 1; i <= 10; i++ ){
System.out.println(i)
}
}
}#This code is contributed by Subhashish Nabajja
Code:
import time
import threading
def myfunc():
print("myfunc started")
print("A Single thread example")
time.sleep(10)
print("myfunc ended")
if __name__ == '__main__':
print('main started')
t = threading.Thread(target=myfunc)
t.start()
print("main ended")
#This code is contributed by Varaliya Mohammed