• Log InLog In
  • Register
Liquid`
Team Liquid Liquipedia
EST 01:34
CET 07:34
KST 15:34
  • 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 Season 3 - Playoffs Preview0RSL Season 3 - RO16 Groups C & D Preview0RSL Season 3 - RO16 Groups A & B Preview2TL.net Map Contest #21: Winners12Intel X Team Liquid Seoul event: Showmatches and Meet the Pros10
Community News
RSL Season 3: RO16 results & RO8 bracket12Weekly Cups (Nov 10-16): Reynor, Solar lead Zerg surge1[TLMC] Fall/Winter 2025 Ladder Map Rotation14Weekly Cups (Nov 3-9): Clem Conquers in Canada4SC: Evo Complete - Ranked Ladder OPEN ALPHA12
StarCraft 2
General
RSL Season 3: RO16 results & RO8 bracket SC: Evo Complete - Ranked Ladder OPEN ALPHA RSL Season 3 - Playoffs Preview Mech is the composition that needs teleportation t GM / Master map hacker and general hacking and cheating thread
Tourneys
RSL Revival: Season 3 $5,000+ WardiTV 2025 Championship StarCraft Evolution League (SC Evo Biweekly) Constellation Cup - Main Event - Stellar Fest 2025 RSL Offline Finals Dates + Ticket Sales!
Strategy
Custom Maps
Map Editor closed ?
External Content
Mutation # 500 Fright night Mutation # 499 Chilling Adaptation Mutation # 498 Wheel of Misfortune|Cradle of Death Mutation # 497 Battle Haredened
Brood War
General
Data analysis on 70 million replays A cwal.gg Extension - Easily keep track of anyone soO on: FanTaSy's Potential Return to StarCraft [ASL20] Ask the mapmakers — Drop your questions FlaSh on: Biggest Problem With SnOw's Playstyle
Tourneys
[Megathread] Daily Proleagues Small VOD Thread 2.0 [BSL21] GosuLeague T1 Ro16 - Tue & Thu 22:00 CET [BSL21] RO16 Tie Breaker - Group B - Sun 21:00 CET
Strategy
Current Meta Game Theory for Starcraft How to stay on top of macro? PvZ map balance
Other Games
General Games
Stormgate/Frost Giant Megathread EVE Corporation Path of Exile [Game] Osu! Should offensive tower rushing be viable in RTS games?
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
Mafia Game Mode Feedback/Ideas
Community
General
Russo-Ukrainian War Thread US Politics Mega-thread The Games Industry And ATVI Things Aren’t Peaceful in Palestine About SC2SEA.COM
Fan Clubs
White-Ra Fan Club The herO Fan Club!
Media & Entertainment
[Manga] One Piece Movie Discussion! Anime Discussion Thread Korean Music Discussion
Sports
2024 - 2026 Football Thread Formula 1 Discussion NBA General Discussion MLB/Baseball 2023 TeamLiquid Health and Fitness Initiative For 2023
World Cup 2022
Tech Support
TL Community
The Automated Ban List
Blogs
The Health Impact of Joining…
TrAiDoS
Dyadica Evangelium — Chapt…
Hildegard
Saturation point
Uldridge
DnB/metal remix FFO Mick Go…
ImbaTosS
Customize Sidebar...

Website Feedback

Closed Threads



Active: 1960 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
Poland17450 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
Poland17450 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
Turkey779 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
Poland17450 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
Next event in 57m
[ Submit Event ]
Live Streams
Refresh
StarCraft: Brood War
PianO 3421
Zeus 516
HiyA 34
Hm[arnc] 5
Bale 4
Dota 2
monkeys_forever499
NeuroSwarm101
League of Legends
JimRising 468
Counter-Strike
Coldzera 617
Other Games
summit1g15715
fl0m532
WinterStarcraft461
C9.Mang0331
Trikslyr41
Organizations
Other Games
gamesdonequick978
StarCraft: Brood War
UltimateBattle 130
StarCraft 2
Blizzard YouTube
StarCraft: Brood War
BSLTrovo
sctven
[ Show 14 non-featured ]
StarCraft 2
• Berry_CruncH210
• Adnapsc2 7
• AfreecaTV YouTube
• intothetv
• Kozan
• IndyKCrew
• LaughNgamezSOOP
• Migwel
• sooper7s
StarCraft: Brood War
• BSLYoutube
• STPLYoutube
• ZZZeroYoutube
League of Legends
• Rush1685
• Lourlo1177
Upcoming Events
RSL Revival
57m
Classic vs MaxPax
SHIN vs Reynor
herO vs Maru
WardiTV Korean Royale
5h 27m
SC Evo League
5h 57m
IPSL
10h 27m
Julia vs Artosis
JDConan vs DragOn
OSC
10h 27m
BSL 21
13h 27m
TerrOr vs Aeternum
HBO vs Kyrie
RSL Revival
1d
Wardi Open
1d 7h
IPSL
1d 13h
StRyKeR vs OldBoy
Sziky vs Tarson
BSL 21
1d 13h
StRyKeR vs Artosis
OyAji vs KameZerg
[ Show More ]
OSC
1d 16h
OSC
2 days
Monday Night Weeklies
2 days
OSC
2 days
Wardi Open
3 days
Replay Cast
4 days
Wardi Open
4 days
Tenacious Turtle Tussle
4 days
The PondCast
5 days
Replay Cast
5 days
LAN Event
6 days
Replay Cast
6 days
Liquipedia Results

Completed

Proleague 2025-11-16
Stellar Fest: Constellation Cup
Eternal Conflict S1

Ongoing

C-Race Season 1
IPSL Winter 2025-26
KCM Race Survival 2025 Season 4
SOOP Univ League 2025
YSL S2
BSL Season 21
CSCL: Masked Kings S3
SLON Tour Season 2
RSL Revival: Season 3
META Madness #9
BLAST Rivals Fall 2025
IEM Chengdu 2025
PGL Masters Bucharest 2025
Thunderpick World Champ.
CS Asia Championships 2025
ESL Pro League S22
StarSeries Fall 2025
FISSURE Playground #2

Upcoming

BSL 21 Non-Korean Championship
Acropolis #4
IPSL Spring 2026
HSC XXVIII
RSL Offline Finals
WardiTV 2025
IEM Kraków 2026
BLAST Bounty Winter 2026
BLAST Bounty Winter 2026: Closed Qualifier
eXTREMESLAND 2025
ESL Impact League Season 8
SL Budapest Major 2025
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 © 2025 TLnet. All Rights Reserved.