Official Everybody Edits Forums

Do you think I could just leave this part blank and it'd be okay? We're just going to replace the whole thing with a header image anyway, right?

You are not logged in.

#1 Before February 2015

hiimsomething
Guest

[Question] Help with multithreading

Is it possible to start the same thread 5 times but it doesn't work. I have no idea how to solve it

Thread Insert; Insert = new Thread(hi); Insert.Start(); Thread.sleep(20); Insert = new Thread(hi); Insert.Start(); Thread.sleep(20); Insert = new Thread(hi); Insert.Start();

Like how 5 different squares (10x10) are filled at the same just starting at different times.

#2 Before February 2015

Tako
Member
From: Memphis, Tennessee, USA
Joined: 2015-08-10
Posts: 6,663
Website

Re: [Question] Help with multithreading

When you reassign`Insert`, the thread stops and is replaced by a new one.

The solution is to create different Thread objects instead of using the same one. For example,

List<Thread> insertThreads = new List<Thread>(); for (int i = 0; i < 5; i++) {     insertThreads.Add(new Thread(hi));     insertThreads[i].Start();     Thread.Sleep(20); }

or just

Thread Insert = new Thread(hi); Insert.Start(); Thread.sleep(20);  Thread Insert2 = new Thread(hi); Insert.Start(); Thread.sleep(20);  Thread Insert3 = new Thread(hi); Insert.Start();


Yeah, well, you know that's just like, uh, your opinion, man.

Offline

#3 Before February 2015

hiimsomething
Guest

Re: [Question] Help with multithreading

thanks tako it works

#4 Before February 2015

Buzzerbee
Forum Admin
From: Texas, U.S.A.
Joined: 2015-02-15
Posts: 4,570

Re: [Question] Help with multithreading

Tako wrote:

or just

Thread Insert = new Thread(hi); Insert.Start(); Thread.Sleep(20);  Thread Insert2 = new Thread(hi); Insert2.Start(); Thread.Sleep(20);  Thread Insert3 = new Thread(hi); Insert3.Start();

Fixed that bit for you.

Last edited by BuzzerBee (Aug 10 2014 11:11:20 pm)


TdQRyz3.png
https://wiki.everybodyedits.com/images/5/5d/135_bee

Offline

#5 Before February 2015

hiimsomething
Guest

Re: [Question] Help with multithreading

why does sometimes, I made 5 threads, it skips 1 block each thread. I set it to Thread.Sleep(50); and 1 block still get skipped
ex: x:32,y:41 draws a block. x++ x:33,41 was skipped, x: 34,41 draws a block.

#6 Before February 2015

Hexagon
Member
Joined: 2015-04-22
Posts: 1,213

Re: [Question] Help with multithreading

This could be because the delay between writing blocks is too small, assuming that each thread is a separate instance of the PlayerIO client. Increasing the delay usually helps.

Offline

#7 Before February 2015

hiimsomething
Guest

Re: [Question] Help with multithreading

@hexagon yep increasing delay help. Are there like ways to detect if something was skipped?

#8 Before February 2015

Tako
Member
From: Memphis, Tennessee, USA
Joined: 2015-08-10
Posts: 6,663
Website

Re: [Question] Help with multithreading

Yes.

Whenever you build a brick, you should get a response from the Connection's OnMessage. Assuming you know how to read the "b" message, it's just a matter of checking if you received the ones you attempted to place.

One option is to have a list of Block objects, and to add new ones to the list when you want to build them. Have a thread running that constantly places what is in the list. In the response to "b" messages, remove items from the list.

You can adapt this idea to incorporate multithreading by having several different lists, adding blocks to the list with the fewest amount of items, and having each thread run a function that constantly places using its own connection.

It's a little complicated but definitely possible. It's also worth your time, because if you can establish a working system that uses multithreading and block verification, you can be 100% certain that all your blocks will be sent to their destination, and very quickly.


Yeah, well, you know that's just like, uh, your opinion, man.

Offline

#9 Before February 2015

hiimsomething
Guest

Re: [Question] Help with multithreading

works perfectly //forums.everybodyedits.com/img/smilies/smile

#10 Before February 2015

Hexagon
Member
Joined: 2015-04-22
Posts: 1,213

Re: [Question] Help with multithreading

Just a quick question; if a block is sent when a block event is received (under your user id) wouldn't that be double the minimum time it would be? So theoretically if the time was averaged and halved would be the time to send blocks to maximize the connection bandwidth.

Offline

hiimsomething 1423758198203234

Board footer

Powered by FluxBB

[ Started around 1713459058.8417 - Generated in 0.039 seconds, 12 queries executed - Memory usage: 1.43 MiB (Peak: 1.55 MiB) ]