• Log InLog In
  • Register
Liquid`
Team Liquid Liquipedia
EST 16:01
CET 22:01
KST 06:01
  • Home
  • Forum
  • Calendar
  • Streams
  • Liquipedia
  • Features
  • Store
  • EPT
  • TL+
  • StarCraft 2
  • Brood War
  • Smash
  • Heroes
  • Counter-Strike
  • Overwatch
  • Liquibet
  • Fantasy StarCraft
  • TLPD
  • StarCraft 2
  • Brood War
  • Blogs
Forum Sidebar
Events/Features
News
Featured News
RSL Revival - 2025 Season Finals Preview8RSL Season 3 - Playoffs Preview0RSL Season 3 - RO16 Groups C & D Preview0RSL Season 3 - RO16 Groups A & B Preview2TL.net Map Contest #21: Winners12
Community News
$21,000 Rongyi Cup Season 3 announced (Jan 22-Feb 7)8Weekly Cups (Dec 29-Jan 4): Protoss rolls, 2v2 returns6[BSL21] Non-Korean Championship - Starts Jan 103SC2 All-Star Invitational: Jan 17-1822Weekly Cups (Dec 22-28): Classic & MaxPax win, Percival surprises3
StarCraft 2
General
Chinese SC2 server to reopen; live all-star event in Hangzhou Weekly Cups (Dec 29-Jan 4): Protoss rolls, 2v2 returns SC2 All-Star Invitational: Jan 17-18 Weekly Cups (Dec 22-28): Classic & MaxPax win, Percival surprises Starcraft 2 Zerg Coach
Tourneys
$21,000 Rongyi Cup Season 3 announced (Jan 22-Feb 7) WardiTV Winter Cup WardiTV Mondays SC2 AI Tournament 2026 OSC Season 13 World Championship
Strategy
Simple Questions Simple Answers
Custom Maps
Map Editor closed ?
External Content
Mutation # 507 Well Trained Mutation # 506 Warp Zone Mutation # 505 Rise From Ashes Mutation # 504 Retribution
Brood War
General
Potential ASL qualifier breakthroughs? BGH Auto Balance -> http://bghmmr.eu/ I would like to say something about StarCraft BW General Discussion StarCraft & BroodWar Campaign Speedrun Quest
Tourneys
[Megathread] Daily Proleagues [BSL21] Grand Finals - Sunday 21:00 CET [BSL21] Non-Korean Championship - Starts Jan 10 SLON Grand Finals – Season 2
Strategy
Game Theory for Starcraft Simple Questions, Simple Answers Current Meta [G] How to get started on ladder as a new Z player
Other Games
General Games
Mechabellum Beyond All Reason Stormgate/Frost Giant Megathread Awesome Games Done Quick 2026! General RTS Discussion Thread
Dota 2
Official 'what is Dota anymore' discussion
League of Legends
Heroes of the Storm
Simple Questions, Simple Answers Heroes of the Storm 2.0
Hearthstone
Deck construction bug Heroes of StarCraft mini-set
TL Mafia
Vanilla Mini Mafia Mafia Game Mode Feedback/Ideas
Community
General
US Politics Mega-thread European Politico-economics QA Mega-thread Russo-Ukrainian War Thread Things Aren’t Peaceful in Palestine Trading/Investing Thread
Fan Clubs
White-Ra Fan Club
Media & Entertainment
Anime Discussion Thread
Sports
2024 - 2026 Football Thread Formula 1 Discussion
World Cup 2022
Tech Support
Computer Build, Upgrade & Buying Resource Thread
TL Community
The Automated Ban List TL+ Announced
Blogs
Life Update and thoughts.
FuDDx
How do archons sleep?
8882
Psychological Factors That D…
TrAiDoS
James Bond movies ranking - pa…
Topin
StarCraft improvement
iopq
Customize Sidebar...

Website Feedback

Closed Threads



Active: 2352 users

The Big Programming Thread - Page 806

Forum Index > General Forum
Post a Reply
Prev 1 804 805 806 807 808 1032 Next
Thread Rules
1. This is not a "do my homework for me" thread. If you have specific questions, ask, but don't post an assignment or homework problem and expect an exact solution.
2. No recruiting for your cockamamie projects (you won't replace facebook with 3 dudes you found on the internet and $20)
3. If you can't articulate why a language is bad, don't start slinging shit about it. Just remember that nothing is worse than making CSS IE6 compatible.
4. Use [code] tags to format code blocks.
Deleted User 3420
Profile Blog Joined May 2003
24492 Posts
Last Edited: 2016-11-28 03:46:06
November 28 2016 03:42 GMT
#16101
edit 2:

okay i edited the original
i dunno what I was doing before
it makes sense now right?
Blitzkrieg0
Profile Blog Joined August 2010
United States13132 Posts
Last Edited: 2016-11-28 04:22:26
November 28 2016 04:17 GMT
#16102
Was trying to think up a way to explain this without just giving you the solution, but its all syntax so hopefully you will look through it and learn something. If you have any questions about why I did things this way I can answer.

+ Show Spoiler +
import java.util.Random;

public class MathWithMultipleThreads {

private static Random random = new Random();
private static int HEIGHT = 1000;
private static int WIDTH = 1000;

private static double[][] makeArray(int height, int width) {
double[][] answer = new double[height][width];
for (int row = 0; row < height; row++) {
for (int col = 0; col < width; col++) {
answer[row][col] = random.nextDouble();
}
}
return answer;
}

public static void main(String[] args) throws InterruptedException {
double[][] array = makeArray(HEIGHT, WIDTH);
long start = System.nanoTime();

Thread[] threads = new Thread[HEIGHT];

for (int i = 0; i < HEIGHT; i++) {
threads[i] = new Thread(new ProcessRow(array[i]));
threads[i].start();
}

for (int i = 0; i < HEIGHT; i++) {
threads[i].join();
}

long end = System.nanoTime();
System.out.println((end - start) / 1000000000.0);
}
}

public class ProcessRow implements Runnable {

double[] row;

public ProcessRow(double[] row) {
this.row = row;
}

@Override
public void run() {
for (int i = 0; i < row.length; i++){
row[i] = Math.sqrt(row[i]);
}
}
}


As an additional exercise, change my code so that it only makes 4 threads, but still finds the squareroot of all the data properly. I'd say that has more practical use if nothing else.
I'll always be your shadow and veil your eyes from states of ain soph aur.
ZigguratOfUr
Profile Blog Joined April 2012
Iraq16955 Posts
November 28 2016 04:19 GMT
#16103
Nietzsche once said that "State is the name of the coldest of all cold monsters." Does that mean Nietzsche was a functional programmer?
Deleted User 3420
Profile Blog Joined May 2003
24492 Posts
Last Edited: 2016-11-28 04:35:58
November 28 2016 04:27 GMT
#16104


//declare an array of threads, intialize it to height elements
Thread[] threads = new Thread[HEIGHT];

//go through each element and say that the thread contains ProcessRow
//is this accurate? And can you only do this because ProcessRow is "runnable" ?
for (int i = 0; i < HEIGHT; i++) {
threads[i] = new Thread(new ProcessRow(array[i]));

//you also start the thread (it does run() at this point? )
threads[i].start();
}

//what does join do exactly? makes it so the program stops executing until whatever threads are executing have all caught up?

for (int i = 0; i < HEIGHT; i++) {
threads[i].join();
}





thanks btw. exactly what I needed. Not as confusing as I expected.
Blisse
Profile Blog Joined July 2010
Canada3710 Posts
Last Edited: 2016-11-28 04:32:10
November 28 2016 04:31 GMT
#16105
Are you just taking a general intro to programming course travis?

Or is all of this part of a program and your questions are from a variety of courses?

I've never taken a single course that covered this much variety in material.
There is no one like you in the universe.
Deleted User 3420
Profile Blog Joined May 2003
24492 Posts
November 28 2016 04:34 GMT
#16106
It's a single course. "Object Oriented Programming 2"
Blitzkrieg0
Profile Blog Joined August 2010
United States13132 Posts
Last Edited: 2016-11-28 12:54:53
November 28 2016 04:37 GMT
#16107
On November 28 2016 13:27 travis wrote:


//declare an array of threads, intialize it to height elements
Thread[] threads = new Thread[HEIGHT];

//go through each element and say that the thread contains ProcessRow
//is this accurate? And can you only do this because ProcessRow is "runnable" ?
for (int i = 0; i < HEIGHT; i++) {
threads[i] = new Thread(new ProcessRow(array[i]));

//you also start the thread (it does run() at this point? )
threads[i].start();
}

//what does join do exactly? makes it so the program stops executing until whatever threads are executing have all //caught up?

for (int i = 0; i < HEIGHT; i++) {
threads[i].join();
}



thanks btw. exactly what I needed. Not as confusing as I expected.


1. as specified in problem statement

2. We're creating all the threads in this step. Each element of threads is one of the threads and the index happens to coincide nicely with each index of array we're processing. Thread has a constructor which takes a Runnable as a parameter. I've always seen Thread extended instead of implementing Runnable personally, but this works.

3. I could/should have called run() in this step. It does the same thing though.

4. Join blocks until the thread is finished processing. We ensure that each thread has finished its math with the join. I'm not sure how much you know about CPUs, processes, threads and the operating system, but I also lack the expertise to explain it well. I'd say its highly questionable to learn about threading without any knowledge of these topics though.
I'll always be your shadow and veil your eyes from states of ain soph aur.
Manit0u
Profile Blog Joined August 2004
Poland17587 Posts
November 28 2016 06:30 GMT
#16108
On November 28 2016 13:19 ZigguratOfUr wrote:
Nietzsche once said that "State is the name of the coldest of all cold monsters." Does that mean Nietzsche was a functional programmer?


Nietzsche was talking in terms of state as a country though
Time is precious. Waste it wisely.
Nesserev
Profile Blog Joined January 2011
Belgium2760 Posts
November 28 2016 07:16 GMT
#16109
--- Nuked ---
Targe
Profile Blog Joined February 2012
United Kingdom14103 Posts
November 28 2016 08:01 GMT
#16110
On November 28 2016 10:24 Manit0u wrote:
I think that the first thing you should work on is structuring your data properly:


tree->left->right->left->left


Holy hell...

Also, may I ask why do you want to introduce closures in C? C is not a functional language and trying to make it so isn't going to help you.

Edit: I assume you have seen this already?

The course I'm doing this in is 'advanced compilers', the closure is how we've been taught to introduce function calls

As for the data structure, that tree->left->right stuff is me navigating the abstract syntax tree to get the required nodes (e.g. In that example the current position in the tree is at the base of a function definition and that navigates to either the location of the function name, base of the function body or arguments) generated from the inputted c program, the parser was provided code so I can't make changes.

I am however quite overwhelmed with the course and the way I've done things is definitely not the best way
11/5/14 CATACLYSM | The South West's worst Falco main
emperorchampion
Profile Blog Joined December 2008
Canada9496 Posts
November 28 2016 08:02 GMT
#16111
Schrodinger's bug
TRUEESPORTS || your days as a respected member of team liquid are over
icystorage
Profile Blog Joined November 2008
Jollibee19350 Posts
November 28 2016 08:05 GMT
#16112
I had a job interview last week (I already have a job) for a mid level position. During the technical interview Q&A, I only answered around 40% of the total questions, is that normal?
LiquidDota StaffAre you ready for a Miracle-? We are! The International 2017 Champions!
Targe
Profile Blog Joined February 2012
United Kingdom14103 Posts
November 28 2016 08:18 GMT
#16113
Also I have a java question, why would you ever extend thread instead of implementing runnable?

Always wondered
11/5/14 CATACLYSM | The South West's worst Falco main
Manit0u
Profile Blog Joined August 2004
Poland17587 Posts
Last Edited: 2016-11-28 09:51:22
November 28 2016 09:45 GMT
#16114
Interesting read about JS: http://bonsaiden.github.io/JavaScript-Garden/

They point out some interesting pitfalls you can run into.

On November 28 2016 17:18 Targe wrote:
Also I have a java question, why would you ever extend thread instead of implementing runnable?

Always wondered


Thread already implements Runnable. The thing is, it comes with plenty of methods already defined so that you don't have to do that yourself (Runnable only has the run() prototype, so no start, stop, suspend, join etc.)...
Time is precious. Waste it wisely.
mantequilla
Profile Blog Joined June 2012
Turkey781 Posts
November 28 2016 09:47 GMT
#16115
is there a windows equivalent to "command &" in linux? like run program and return to console
Age of Mythology forever!
Manit0u
Profile Blog Joined August 2004
Poland17587 Posts
Last Edited: 2016-11-28 09:54:46
November 28 2016 09:53 GMT
#16116
On November 28 2016 18:47 mantequilla wrote:
is there a windows equivalent to "command &" in linux? like run program and return to console



start /B command


http://www.computerhope.com/starthlp.htm
Time is precious. Waste it wisely.
Targe
Profile Blog Joined February 2012
United Kingdom14103 Posts
November 28 2016 10:13 GMT
#16117
On November 28 2016 18:45 Manit0u wrote:
Interesting read about JS: http://bonsaiden.github.io/JavaScript-Garden/

They point out some interesting pitfalls you can run into.

Show nested quote +
On November 28 2016 17:18 Targe wrote:
Also I have a java question, why would you ever extend thread instead of implementing runnable?

Always wondered


Thread already implements Runnable. The thing is, it comes with plenty of methods already defined so that you don't have to do that yourself (Runnable only has the run() prototype, so no start, stop, suspend, join etc.)...


Ah that clears that up then
11/5/14 CATACLYSM | The South West's worst Falco main
Blitzkrieg0
Profile Blog Joined August 2010
United States13132 Posts
Last Edited: 2016-11-28 12:55:19
November 28 2016 12:50 GMT
#16118
I'll always be your shadow and veil your eyes from states of ain soph aur.
RoomOfMush
Profile Joined March 2015
1296 Posts
November 28 2016 15:22 GMT
#16119
On November 28 2016 17:18 Targe wrote:
Also I have a java question, why would you ever extend thread instead of implementing runnable?

Always wondered

The standard way is to implement Runnable. Extending Thread is possible but doesnt give you any benefits. Thread does not have any protected methods or fields. The idea behind implementing Runnable is separation of concerns. The Thread class takes care of all the complicated stuff and the runnable defines the behavior like a Strategy pattern.

On November 28 2016 18:45 Manit0u wrote:
Interesting read about JS: http://bonsaiden.github.io/JavaScript-Garden/

They point out some interesting pitfalls you can run into.

Show nested quote +
On November 28 2016 17:18 Targe wrote:
Also I have a java question, why would you ever extend thread instead of implementing runnable?

Always wondered


Thread already implements Runnable. The thing is, it comes with plenty of methods already defined so that you don't have to do that yourself (Runnable only has the run() prototype, so no start, stop, suspend, join etc.)...

You should not use the stop() or suspend() methods on Threads in java. There was even talk about removing them from Java 8 (by having them always throw exceptions) and breaking backwards compatibility. Thats how bad they are.
Targe
Profile Blog Joined February 2012
United Kingdom14103 Posts
November 28 2016 16:01 GMT
#16120
yeah runnable was how i learned to implement threads when i had to learn java i dont think ive ever extended thread
11/5/14 CATACLYSM | The South West's worst Falco main
Prev 1 804 805 806 807 808 1032 Next
Please log in or register to reply.
Live Events Refresh
AI Arena Tournament
20:00
Swiss - Round 1
Laughngamez YouTube
PSISTORM Gaming Misc
16:55
FSL s9 Code A & S Championship
Freeedom53
Liquipedia
Big Gabe XPERIONCRAFT
13:00
#3
RotterdaM3525
IndyStarCraft 402
mouzHeroMarine203
Belair 59
Liquipedia
[ Submit Event ]
Live Streams
Refresh
StarCraft 2
RotterdaM 3525
IndyStarCraft 402
PiGStarcraft290
mouzHeroMarine 203
UpATreeSC 46
Nathanias 29
StarCraft: Brood War
Shuttle 636
ZZZero.O 205
Dewaltoss 121
Rock 36
Dota 2
Gorgc5595
Pyrionflax137
LuMiX1
Counter-Strike
fl0m5667
Super Smash Bros
hungrybox449
Mew2King37
Heroes of the Storm
Liquid`Hasu571
Other Games
summit1g4580
Grubby4435
FrodaN3935
Beastyqt696
B2W.Neo201
XaKoH 173
KnowMe143
QueenE84
ToD1
Organizations
Other Games
gamesdonequick62043
StarCraft 2
ComeBackTV 1034
Other Games
EGCTV1009
BasetradeTV34
StarCraft 2
angryscii 26
Blizzard YouTube
StarCraft: Brood War
BSLTrovo
sctven
[ Show 20 non-featured ]
StarCraft 2
• printf 31
• davetesta12
• Adnapsc2 8
• IndyKCrew
• Kozan
• Migwel
• intothetv
• sooper7s
• AfreecaTV YouTube
• LaughNgamezSOOP
StarCraft: Brood War
• 80smullet 21
• FirePhoenix12
• HerbMon 8
• STPLYoutube
• ZZZeroYoutube
• BSLYoutube
Dota 2
• masondota2565
• HappyZerGling85
League of Legends
• Nemesis3969
Other Games
• imaqtpie2431
Upcoming Events
WardiTV Invitational
15h 59m
ByuN vs Percival
Percival vs Rogue
Percival vs Classic
ByuN vs Classic
ByuN vs Rogue
Classic vs Rogue
IPSL
22h 59m
DragOn vs Sziky
Replay Cast
1d 11h
Wardi Open
1d 14h
Monday Night Weeklies
1d 19h
WardiTV Invitational
2 days
WardiTV Invitational
3 days
The PondCast
4 days
All Star Teams
6 days
INnoVation vs soO
sOs vs Scarlett
CranKy Ducklings
6 days
[ Show More ]
uThermal 2v2 Circuit
6 days
Liquipedia Results

Completed

Escore Tournament S1: W3
WardiTV 2025
META Madness #9

Ongoing

C-Race Season 1
IPSL Winter 2025-26
BSL 21 Non-Korean Championship
Proleague 2026-01-10
OSC Championship Season 13
Big Gabe Cup #3
Underdog Cup #3
eXTREMESLAND 2025
SL Budapest Major 2025
ESL Impact League Season 8
BLAST Rivals Fall 2025
IEM Chengdu 2025
PGL Masters Bucharest 2025

Upcoming

CSL 2025 WINTER (S19)
Escore Tournament S1: W4
Acropolis #4
IPSL Spring 2026
Bellum Gens Elite Stara Zagora 2026
HSC XXVIII
Rongyi Cup S3
Thunderfire SC2 All-star 2025
Nations Cup 2026
NA Kuram Kup
BLAST Open Spring 2026
ESL Pro League Season 23
ESL Pro League Season 23
PGL Cluj-Napoca 2026
IEM Kraków 2026
BLAST Bounty Winter 2026
BLAST Bounty Winter Qual
TLPD

1. ByuN
2. TY
3. Dark
4. Solar
5. Stats
6. Nerchio
7. sOs
8. soO
9. INnoVation
10. Elazer
1. Rain
2. Flash
3. EffOrt
4. Last
5. Bisu
6. Soulkey
7. Mini
8. Sharp
Sidebar Settings...

Advertising | Privacy Policy | Terms Of Use | Contact Us

Original banner artwork: Jim Warren
The contents of this webpage are copyright © 2026 TLnet. All Rights Reserved.