• Advertisement
Sign in to follow this  

Unity better programming languages to support multiple Threads

This topic is 4201 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Well, dual core processors are now going to be the standard for low end pcs thanks to the new price wars from Intel and AMD. And it's a shame that only one core will really be used most of the time since 99% of the programs out there are still single threaded. I think the reason for this is quite obvious, we just don't have a good programming language to support easy development of Threads. With the state of current languages it is easy enough to create a Thread, and run it. But, we really need something even easier if we want more Threaded programs. I think there is a good opportunity for Java or C# to introduce new syntax for each language and it's JIT compiler to automattically make the program multi-threaded if it detects a core not being utilized. lets say you had 3 methods, and all 3 methods could be executed at the same time, but all 3 needed to be done before the fourth method executed. - with new language syntax this could be achieved like this: public void someMethodToRunTasks() { executeTask1() can run asynchrously executeTask2() can run asynchrously executeTask3() can run asynchrously executeTask4() depends on executeTask1, executeTask2, executeTask3 } then the respective JIT compiler could then take those dependencies and automattically create the best possible threaded program without the programmer doing anything except specifying the dependencies. Of course i don't think it's this simple (there would still be additional rules and behavior to be defined) but I think this is definitely doable, and would encourage development of multithreaded apps.

Share this post


Link to post
Share on other sites
Advertisement
Have you checked http://en.wikipedia.org/wiki/Concurrent_programming and http://en.wikipedia.org/wiki/Software_transactional_memory?

A lot of your ideas are already realized in software, just not in plain C# or Java.

OpenMP makes it easy to add multithreading in C/C++/Fortran for trivially parallelizeable stuff like your example.

It would look somewhat like that (not tested, but I think it's right that way):
void someMethodToRunTasks()
{
#pragma OMP parallel sections
{
#pramga OMP section
executeTask1();
#pragma OMP section
executeTask2();
#pragma OMP section
executeTask3();
}
executeTask4();
}


[Edited by - Trap on July 22, 2006 11:09:27 AM]

Share this post


Link to post
Share on other sites
I believe Mutexes and Semaphores are busted in the .NET Framework 2.0 (Or at least lacking a full implementation). Thus, I don't recommend C#.

Share this post


Link to post
Share on other sites
There's a lot of research going on in this area. Take a look at this presentation by Herb Sutter for some discussion about how to extend languages like C# and C++ to support higher level abstractions for concurrency.

Share this post


Link to post
Share on other sites
There are 3 basic forms of concurrency seen in languages.

  1. Declarative concurrency. The simplest form, and the easiest to work with. You spawn off a purely functional function, let it do its work in parallel, and when you need the value it returns and try to use it, the system waits for the thread to terminate and yield its result.

  2. Message passing concurrency. Threads communicate via messages. Not quite as simple and as easy to reason about as option 1, but very powerful and relatively straightforward.

  3. Shared state concurrency. This is the model languages like C++ and C# are mostly stuck with. The combination of mutable variables with concurrency is very hard to reason about for a range of reasons. No need to be the default. When it is used, software transactional memory is a good technique for getting around having to use low level locks.

Oz and Alice feature all models. Erlang is built around message passing concurrency. The problem of handling concurrency has actually been adequately solved for some time, although no mainstream languages provide good support. Sutter's Concur project aims to bring support for message passing concurrency to C++, and Microsoft Research have been experimenting on adding features from join calculus to C#.

Share this post


Link to post
Share on other sites
Quote:
Original post by Thevenin
I believe Mutexes and Semaphores are busted in the .NET Framework 2.0 (Or at least lacking a full implementation). Thus, I don't recommend C#.


Could you be a bit more specific? What exactly is busted, and how is it busted? Are we talking about bugs or just missing features? If there's a problem with concurrency in .NET, I'd rather know it *before* I run into a situation where I have to debug it... [grin]

Share this post


Link to post
Share on other sites
Quote:
Original post by Spoonbender
Quote:
Original post by Thevenin
I believe Mutexes and Semaphores are busted in the .NET Framework 2.0 (Or at least lacking a full implementation). Thus, I don't recommend C#.


Could you be a bit more specific? What exactly is busted, and how is it busted? Are we talking about bugs or just missing features? If there's a problem with concurrency in .NET, I'd rather know it *before* I run into a situation where I have to debug it... [grin]
I, too, would like to know what the hell you're talking about. Sounds like one of those "somebody somewhere mentioned it at some point, therefore it's fact" type things.

Oh, and I think everybody should read the wikipedia article on Software Transactional Memory.

Share this post


Link to post
Share on other sites
Have a look at ADA for high level built in concurrency.

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
the only thing close to Thevenin's post that i'm aware of is the extremely suboptimal performance of readerwriterlock in the .net framework 2.0 .. nothing known to me otherwise concerning thread synchronization and the .net framework.

i suppose c#-wise it would be of great interest to grab the concurrency coordination runtime, CCR. currently it is only available via the robotics framework by microsoft into which the CCR has been integrated as its functionality is key to the robotics framework.

cheers,
simon

Share this post


Link to post
Share on other sites
Quote:
# Declarative concurrency. The simplest form, and the easiest to work with. You spawn off a purely functional function, let it do its work in parallel, and when you need the value it returns and try to use it, the system waits for the thread to terminate and yield its result.

# Message passing concurrency. Threads communicate via messages. Not quite as simple and as easy to reason about as option 1, but very powerful and relatively straightforward.

# Shared state concurrency. This is the model languages like C++ and C# are mostly stuck with. The combination of mutable variables with concurrency is very hard to reason about for a range of reasons. No need to be the default. When it is used, software transactional memory is a good technique for getting around having to use low level locks.


It is actually fairly simple to implement #1 using #3. In C++, I would create a proxy class. Upon creation the proxy would spawn another process to calculate the value. The other process would lock the proxy, calculate it, and unlock it. The original process would block on the lock when it tried to access the proxy. You do need a tad more book keeping to avoid a race condition. It would look something like this, in psuedo C++.


class proxy
{
T value;
Event is_ready; //Event is some concurency primitive that once triggered,
//remains always triggered. IIRC, the 'events' in the
//windows API don't have this behavior

//You might even be able to use a bool (reads are atomic operations)
//but then you would need a busy loop. :(
public:
proxy()
{
spawn_process(calculate_value,this);
}

T get_value()
{
wait for is_ready;
return value;
}
};

void calculate_value(proxy* p)
{
p->value = the_calculated_value;
trigger p->is_ready;
}

int main()
{
proxy p;
p.get_value();
}

Share this post


Link to post
Share on other sites
Quote:
Original post by Deyja

class proxy
{
T value;
Event is_ready; //Event is some concurency primitive that once triggered,
//remains always triggered. IIRC, the 'events' in the
//windows API don't have this behavior




Yes they do, provided you call the CreateEvent() function with the bManualReset argument passed as TRUE.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
  • Advertisement
  • Popular Tags

  • Advertisement
  • Popular Now

  • Similar Content

    • By 3dmodelerguy
      So I am building a turn based rogue-like (think CDDA). The game is going to have a very large map (up to 1000's x 1000's) however to alleviate most of that I obviously can't render everything so there will just be render a certain radius around the player and just load in and out data as the player moves.
      The next major system I am prototyping is making interactive tiles destructible and pretty much everything will be destructible besides basic landscape (cars, doors, windows, structures, etc. will be destructible)
      While I am only rendering a certain amount of tiles around the player, I want to keep the amount of colliders active at one time to be as small as possible for performance and currently the tilemap tool I use automatically merges colliders together.
      So instead of creating a separate colliders for each of these tiles and having the destructible behavior tied to that object (which my tilemap tool would allow me to do) I was thinking that I would store an array of all the X and Y locations for the interactive tilemap layer and let the tilemap manage the colliders. 
      Then when I hit a collider on the interactive tilemap layer, instead of of getting the behavior for how to deal with the destruction for that tile from that game object, I would pull it from the array I mentioned earlier based on the tile I attempt to interact with which I already have.
      Does this sound like a good approach? Any other recommendations would be welcomed.
    • By NDraskovic
      Hey guys,
      I have a really weird problem. I'm trying to get some data from a REST service. I'm using the following code:
       
      private void GetTheScores() { UnityWebRequest GetCommand = UnityWebRequest.Get(url); UnityWebRequestAsyncOperation operation = GetCommand.SendWebRequest(); if (!operation.webRequest.isNetworkError) { ResultsContainer rez = JsonUtility.FromJson<ResultsContainer>(operation.webRequest.downloadHandler.text); Debug.Log("Text: " + operation.webRequest.downloadHandler.text); } } The problem is that when I'm in Unity's editor, the request doesn't return anything (operation.webRequest.downloadHandler.text is empty, the Debug.Log command just prints "Text: "), but when I enter the debug mode and insert a breakpoint on that line, then it returns the text properly. Does anyone have an idea why is this happening?
      The real problem I'm trying to solve is that when I receive the text, I can't get the data from the JSON. The markup is really simple:
      [{"id":1,"name":"Player1"},{"id":2,"name":"Player2"}] and I have an object that should accept that data:
      [System.Serializable] public class ResultScript { public int id; public string name; } There is also a class that should accept the array of these objects (which the JSON is returning):
      [System.Serializable] public class ResultsContainer { public ResultScript[] results; } But when I run the code (in the debug mode, to get any result) I get an error: ArgumentException: JSON must represent an object type. I've googled it but none of the proposed solutions work for me.
      Also (regardless if I'm in the debug mode or not) when I try to do some string operations like removing or adding characters to the GET result, the functions return an empty string as a result
      Can you help me with any of these problems?
      Thank you
    • By nihitori
      The Emotional Music Vol. I pack focuses on beautiful and esoteric orchestral music, capable of creating truly emotive and intimate moods. It features detailed chamber strings, cello and piano as the main instruments, resulting in a subtle and elegant sound never before heard in video game royalty-free music assets.

      The pack includes 5 original tracks, as well as a total of 47 loops based on these tracks (long loops for simple use and short loops for custom / complex music layering).

      Unity Asset Store link: https://www.assetstore.unity3d.com/en/#!/content/107032
      Unreal Engine Marketplace link: https://www.unrealengine.com/marketplace/emotional-music-vol-i

      A 15 seconds preview of each main track is available on Soundcloud:
       
    • By RoKabium Games
      Another one of our new UI for #screenshotsaturday. This is the inventory screen for showing what animal fossils you have collected so far. #gamedev #indiedev #sama
    • By eldwin11929
      We're looking for programmers for our project.
      Our project is being made in Unity
      Requirements:
      -Skills in Unity
      -C#
      -Javascript
      -Node.js
      We're looking for programmers who can perform a variety of functions on our project.
      Project is a top-down hack-and-slash pvp dungeon-crawler like game. Game is entirely multiplayer based, using randomized dungeons, and a unique combat system with emphasis on gameplay.
      We have a GDD to work off of, and a Lead Programmer you would work under.
      Assignments may include:
      -Creating new scripts of varying degrees specific to the project (mostly server-side, but sometimes client-side)
      -Assembling already created monsters/characters with existing or non-existing code.
      -Creating VFX
      -Assembling already created environment models
      If interested, please contact: eldwin11929@yahoo.com
      This project is unpaid, but with royalties.
       
      ---
      Additional Project Info:
      Summary:
      Bassetune Reapers is a Player-verus-Player, competitive dungeon crawler. This basically takes on aspects of dungeon crawling, but with a more aggressive setting. Players will have the option to play as the "dungeon-crawlers" (called the 'Knights', or "Knight Class", in-game) or as the "dungeon" itself (literally called the 'Bosses', or "Boss Class", in-game). What this means is that players can choose to play as the people invading the dungeon, or as the dungeon-holders themselves.
      Key Features:
      -Intense, fast-paced combat
      -Multiple skills, weapons, and ways to play the game
      -Tons of different Bosses, Minibosses, creatures and traps to utilize throughout the dungeon
      -Multiple unique environments
      -Interesting, detailed lore behind both the game and world
      -Intricate RPG system
      -Ladder and ranking system
      -Lots of customization for both classes s of customization for both classes
  • Advertisement