Python Tutorials- Threading Beginners Tutorials - Locks - part 5

preview_player
Показать описание
This video is part of Python Threading Beginners Tutorial playlist.
If you are new to threads please start the playlist from the
beginning.

The playlist can be found here:

Python Locks -In this video, I will be showing you how to utilize locks with your threads.

Python 3.x - Understanding and utilizing locks with threads -- by Moondra
Рекомендации по теме
Комментарии
Автор

Thank you! Great introduction to locks. I wonder why the errors are so large when they do occur? Is it to do with the fact that that if two functions coincide, it's likely that they'll stay "in sync" for their whole loop?

MobyMotion
Автор

really appreciate your work!..keep doing .

yaservp
Автор

Thankyou for these awesome explanations..!!

shaikzubedi
Автор

Can we abandon the lock statement in the last function ?

junxuanwu
Автор

nice video
But I think the locks are in the wrong places. Your locks will only be unlocked after the whole function is done, basically doing the same as if you call the functions after each other without threading. Put some "print(x)" after all the "x+=2", "x-=1", ... and watch the count go up and then down.
I took the for loops out of the locks and now the threads work as intended.

INTENDR
Автор

Why are you getting random large numbers before using locks? If it is unlikely for two threads to access the variable at the same (usually the result is 0) I'd expect only a single occurrence to cause an offset of only 1, 2, 3 or 4

binklederry
Автор

i think it would better to use fuzzing method, by adding time.sleep(random.random()) inside each function so that non zero result will come up much faster than running the script again and again in terminal

alisherbekrakhimov
Автор

Why don't you have to type:
global COUNT
or
global lock
in the functions? if we did it for x

EchoVidsu
Автор

Is there a difference between join and lock ? I could also call the join after thread1.start() and before calling the next thread2.start(). Then the variable is also "locked" because thread1 is not finished or am I missing something? Thanks a lot

DanielWeikert
Автор

To avoid executing so often, add is_locked flag, "if is_locked: with lock: ...", then loop the thread calls 1, 000 times or so.

hrothcycle
Автор

The threads are running in sequence. One of the threads is first and does all the loops and then when it finishs the next one takes over. So what's the point of a thread here. If you just locked the x -= 1 statement on each one then they would all run.

ahbushnell
Автор

Hey there! Great video as always! What I wanted to ask was I tried your code once using 'lock.acquire - lock.release' method and secondly using 'with' statement. And only the latter produced zeros without any error. Can you discuss how is this possible?

AsadUllahButt
Автор

i have few doubts in this code:
1) with using delay/ time.sleep() it is not a parallel execution or multithreading because thread2 will be executed only when thread1 has to wait for some input. correct me if I'm wrong
2) before using lock only we are getting perfect output zero so no explanation for that

santhoshkumar-tcxp
Автор

I am getting x = 0 everytime(100+ times) i run the program before using locks

mr.progammer
Автор

Come on man, no github ?
You gotta include the code .

jeffreydilley
Автор

I hate to be the bearer of bad news but this does not work. -20000 is the result every time

BabyBallascore
join shbcf.ru