• Log InLog In
  • Register
Liquid`
Team Liquid Liquipedia
EST 11:13
CET 17:13
KST 01:13
  • 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
herO wins SC2 All-Star Invitational5SC2 All-Star Invitational: Tournament Preview5RSL Revival - 2025 Season Finals Preview8RSL Season 3 - Playoffs Preview0RSL Season 3 - RO16 Groups C & D Preview0
Community News
Weekly Cups (Jan 12-18): herO, MaxPax, Solar win0BSL Season 2025 - Full Overview and Conclusion8Weekly Cups (Jan 5-11): Clem wins big offline, Trigger upsets4$21,000 Rongyi Cup Season 3 announced (Jan 22-Feb 7)16Weekly Cups (Dec 29-Jan 4): Protoss rolls, 2v2 returns7
StarCraft 2
General
PhD study /w SC2 - help with a survey! herO wins SC2 All-Star Invitational SC2 Spotted on the EWC 2026 list? Starcraft 2 will not be in the Esports World Cup When will we find out if there are more tournament
Tourneys
OSC Season 13 World Championship $70 Prize Pool Ladder Legends Academy Weekly Open! SC2 All-Star Invitational: Jan 17-18 Sparkling Tuna Cup - Weekly Open Tournament SC2 AI Tournament 2026
Strategy
Simple Questions Simple Answers
Custom Maps
[A] Starcraft Sound Mod
External Content
Mutation # 509 Doomsday Report Mutation # 508 Violent Night Mutation # 507 Well Trained Mutation # 506 Warp Zone
Brood War
General
[ASL21] Potential Map Candidates BW General Discussion BW AKA finder tool Gypsy to Korea BGH Auto Balance -> http://bghmmr.eu/
Tourneys
[Megathread] Daily Proleagues [BSL21] Non-Korean Championship - Starts Jan 10 Small VOD Thread 2.0 Azhi's Colosseum - Season 2
Strategy
Current Meta Simple Questions, Simple Answers Soma's 9 hatch build from ASL Game 2 Game Theory for Starcraft
Other Games
General Games
Battle Aces/David Kim RTS Megathread Nintendo Switch Thread Stormgate/Frost Giant Megathread Beyond All Reason Awesome Games Done Quick 2026!
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 NASA and the Private Sector Canadian Politics Mega-thread Things Aren’t Peaceful in Palestine Russo-Ukrainian War Thread
Fan Clubs
The herO Fan Club! The IdrA Fan Club
Media & Entertainment
Anime Discussion Thread [Manga] One Piece
Sports
2024 - 2026 Football Thread
World Cup 2022
Tech Support
Computer Build, Upgrade & Buying Resource Thread
TL Community
The Automated Ban List
Blogs
Navigating the Risks and Rew…
TrAiDoS
My 2025 Magic: The Gathering…
DARKING
Life Update and thoughts.
FuDDx
How do archons sleep?
8882
James Bond movies ranking - pa…
Topin
Customize Sidebar...

Website Feedback

Closed Threads



Active: 1642 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
Poland17613 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
Poland17613 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
Poland17613 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
OSC
11:00
Season 13 World Championship
Krystianer vs CureLIVE!
ShoWTimE vs TBD
WardiTV1237
IndyStarCraft 269
TKL 231
LiquipediaDiscussion
[ Submit Event ]
Live Streams
Refresh
StarCraft 2
IndyStarCraft 269
TKL 231
Harstem 174
ProTech131
JuggernautJason45
SC2Nice 32
StarCraft: Brood War
Calm 3531
Horang2 808
Mini 459
Snow 162
hero 160
BeSt 148
actioN 141
Mong 138
Hyun 104
Dewaltoss 93
[ Show more ]
JYJ 52
Mind 44
Sexy 44
Killer 34
Rock 31
Hm[arnc] 27
Barracks 26
Terrorterran 22
ajuk12(nOOB) 17
SilentControl 10
JulyZerg 8
Dota 2
qojqva2328
Dendi484
syndereN342
420jenkins222
Counter-Strike
fl0m8148
olofmeister3580
byalli1493
x6flipin666
Other Games
singsing1859
B2W.Neo1097
hiko625
allub343
Hui .268
DeMusliM230
crisheroes217
RotterdaM194
Fuzer 165
Sick125
ArmadaUGS111
oskar84
Mew2King32
Rex28
Organizations
StarCraft 2
Blizzard YouTube
StarCraft: Brood War
BSLTrovo
sctven
[ Show 17 non-featured ]
StarCraft 2
• StrangeGG 55
• HeavenSC 13
• poizon28 11
• IndyKCrew
• sooper7s
• AfreecaTV YouTube
• intothetv
• Kozan
• LaughNgamezSOOP
• Laughngamez YouTube
• Migwel
StarCraft: Brood War
• FirePhoenix2
• STPLYoutube
• ZZZeroYoutube
• BSLYoutube
Dota 2
• WagamamaTV314
League of Legends
• TFBlade933
Upcoming Events
Big Brain Bouts
2 days
Serral vs TBD
OSC
2 days
BSL 21
2 days
uThermal 2v2 Circuit
3 days
BSL 21
3 days
Wardi Open
4 days
Monday Night Weeklies
5 days
OSC
5 days
WardiTV Invitational
5 days
WardiTV Invitational
6 days
Liquipedia Results

Completed

Proleague 2026-01-20
SC2 All-Star Inv. 2025
NA Kuram Kup

Ongoing

C-Race Season 1
BSL 21 Non-Korean Championship
CSL 2025 WINTER (S19)
KCM Race Survival 2026 Season 1
OSC Championship Season 13
Underdog Cup #3
BLAST Bounty Winter Qual
eXTREMESLAND 2025
SL Budapest Major 2025
ESL Impact League Season 8
BLAST Rivals Fall 2025
IEM Chengdu 2025

Upcoming

Escore Tournament S1: W5
Acropolis #4 - TS4
Acropolis #4
IPSL Spring 2026
uThermal 2v2 2026 Main Event
Bellum Gens Elite Stara Zagora 2026
HSC XXVIII
Rongyi Cup S3
Nations Cup 2026
PGL Bucharest 2026
Stake Ranked Episode 1
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
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.