[Plugin] MultiThread
#41

Quote:
Originally Posted by jameskmonger
Посмотреть сообщение
Fro1sha, when I use DestroyThread, it shuts down my server - is there any way to stop the thread from continuing without shutting it down?
Show your code. And read first post.
Reply
#42

pawn Код:
// This is a comment
// uncomment the line below if you want to write a filterscript
//#define FILTERSCRIPT

#include <a_samp>
#include <thread>

main()
{
    print("\n----------------------------------");
    print(" Blank Gamemode by your name here");
    print("----------------------------------\n");
}

new tickid, tick2id, ticknumber = 0, tick2number = 0;

public OnGameModeInit()
{
    tickid = CreateThread( "MyFunction" );
    tick2id = CreateThread( "MyFunction2" );
}

public OnGameModeExit()
{
    DestroyThread( tickid );
    DestroyThread( tick2id );
}

forward MyFunction(threadid);
public MyFunction(threadid)
{
    ticknumber++;
    if(ticknumber == 10) {
        printf( "Closing Thread (%d)", tickid );
        LockThread( threadid );
    } else {
        SleepThread( 1000 );
        printf( "tick %d: %d", tickid, ticknumber);
    }
}

forward MyFunction2(threadid);
public MyFunction2(threadid)
{
    tick2number++;
    if(tick2number == 10) {
        printf( "Closing Thread (%d)", threadid );
        LockThread( tick2id );
    } else {
        SleepThread( 2000 );
        printf( "tick %d: %d", tick2id, tick2number);
    }
}
Shuts down when MyFunction reaches 10.
Reply
#43

pawn Код:
// This is a comment
// uncomment the line below if you want to write a filterscript
//#define FILTERSCRIPT

#include <a_samp>
#include <thread>

main()
{
    print("\n----------------------------------");
    print(" Blank Gamemode by your name here");
    print("----------------------------------\n");
}

new tickid, tick2id, ticknumber = 0, tick2number = 0;

public OnGameModeInit()
{
    tickid = CreateThread( "MyFunction" );
    tick2id = CreateThread( "MyFunction2" );
}

public OnGameModeExit()
{
    DestroyThread( tickid );
    DestroyThread( tick2id );
}

forward MyFunction(threadid);
public MyFunction(threadid)
{
    ticknumber++;
    if(ticknumber == 10) {
        printf( "Closing Thread (%d)", tickid );
        LockThread( threadid );
    } else {
        SleepThread( 1000 );
        printf( "tick %d: %d", tickid, ticknumber);
    }
}

forward MyFunction2(threadid);
public MyFunction2(threadid)
{
    tick2number++;
    if(tick2number == 10) {
        printf( "Closing Thread (%d)", threadid );
        LockThread( tick2id );
    } else {
        SleepThread( 2000 );
        printf( "tick %d: %d", tick2id, tick2number);
    }
}
Shuts down when MyFunction reaches 10.
Reply
#44

This Plugin is very nice. I try too make gamemode with this plugin
Reply
#45

I think that this plugin is useful to check something and not to set. It can be used to create and call new powerful callbacks not more not less. Good work
Reply
#46

so what this plugins does do?
Reply
#47

Quote:
Originally Posted by xkirill
Посмотреть сообщение
so what this plugins does do?
SA-MP server runs ONE thread, in which, timers, functions, and other stuff take action.
This is a Multi-Thread, helps you create many threads, in which, timers will work, without consuming much memory.

I think I got it right?
Reply
#48

Quote:
Originally Posted by Zh3r0
Посмотреть сообщение
SA-MP server runs ONE thread, in which, timers, functions, and other stuff take action.
This is a Multi-Thread, helps you create many threads, in which, timers will work, without consuming much memory.

I think I got it right?
aha..ok thanks for explaning
Reply
#49

That's not right. Pages 1-3 and perhaps even more are full of explanations why this plugin is highly impractical for PAWN/SA-MP and will end up crashing. It doesn't have much to do with timers anyways and it won't decrease memory usage for sure.
Reply
#50

I readed all topic, I was so impressed when I read the topic name. I know, now I get flamed for bumping old thread, but I've got some unclear questions.
Is it possible to use this without having any issues?
Is it possible to write multitasking plugin, but it's very hard or it's totally impossible?
Reply
#51

Quote:
Originally Posted by zgintasz
Посмотреть сообщение
I readed all topic, I was so impressed when I read the topic name. I know, now I get flamed for bumping old thread, but I've got some unclear questions.
Is it possible to use this without having any issues?
Is it possible to write multitasking plugin, but it's very hard or it's totally impossible?
There is no way unless you got the source of sa-mp and can edit it to make it multithread-compatible. (and you'd have to wedit pawn aswell because, as far as I know it has no multithread support.)
Reply
#52

Quote:
Originally Posted by Gamer_Z
Посмотреть сообщение
There is no way unless you got the source of sa-mp and can edit it to make it multithread-compatible. (and you'd have to wedit pawn aswell because, as far as I know it has no multithread support.)
This idea came to my mind this morning. Creating gamemode as a plugin and adding multithreading, will it work? Someone should try this.
Reply
#53

Thank you! Very useful plugin.
Reply
#54

Mutex lock doesn't work at random times. Thread still continues.
Reply
#55

This plugin is bunk don't even waste your time with this nonsense.
Reply
#56

Pawn is not thread-safe. This plugin is useful only if you want to crash your server.
Reply
#57

I don't know what is wrong with you guys.

This plugin increases the power of the scripter. You can create background processes with this plugin so user won't have to wait for the loop which does regulary work for all users or any function that has heavy calculations to be done. If you call the loop or the function with the plugin, the server processes users command and the loop and the function at the same time and everything is completed in less time.

Say me a reason to not to use this plugin I'll Shift+Delete my entire script.
Reply
#58

Quote:
Originally Posted by Emre__
Посмотреть сообщение
I don't know what is wrong with you guys.

This plugin increases the power of the scripter. You can create background processes with this plugin so user won't have to wait for the loop which does regulary work for all users or any function that has heavy calculations to be done. If you call the loop or the function with the plugin, the server processes users command and the loop and the function at the same time and everything is completed in less time.

Say me a reason to not to use this plugin I'll Shift+Delete my entire script.
You bumped old thread.

PAWN isn't threadsafe that's big reason why you shouldn't use it.
Reply
#59

Quote:
Originally Posted by Emre__
Посмотреть сообщение
I don't know what is wrong with you guys.

This plugin increases the power of the scripter. You can create background processes with this plugin so user won't have to wait for the loop which does regulary work for all users or any function that has heavy calculations to be done. If you call the loop or the function with the plugin, the server processes users command and the loop and the function at the same time and everything is completed in less time.

Say me a reason to not to use this plugin I'll Shift+Delete my entire script.
THE ANSWER IS RIGHT ABOVE YOU!
Quote:
Originally Posted by Dan..
Посмотреть сообщение
Pawn is not thread-safe. This plugin is useful only if you want to crash your server.
(It's also mentioned a billion times before on this thread)

Basically, the SA:MP Server, RakNet nor Pawn is supposed to be run with multiple threads. With RakNet, if you push something to the client/the server at the same time, a crash is very probable or at least very unstable results.
Using this plugin would require so much caution and workarounds the speed you gain from it doesn't mean shit.
Reply
#60

Quote:
Originally Posted by ******
Посмотреть сообщение
By "PAWN is not threadsafe" we mean that running two threads within PAWN will corrupt data and make you loose information, run code that shouldn't be run, and then just crash.
but I tried this callback on different players and the callback invoked simultaneously and changed the variable value.
here's the code:

PHP код:
new string[180];
public 
OnPlayerCommandText(playeridcmdtext[])
{
    if (
strcmp("/mycommand"cmdtexttrue10) == 0)
    {
        
format(string,sizeof(string),"Bla bla bla %s",blablabla);
        
SendClientMessage(playerid,RED,string);
        return 
1;
    }
    else if (
strcmp("/mycommand2"cmdtexttrue10) == 0)
    {
        
format(string,sizeof(string),"Bla bla bla 2 %s",blablabla2);
        
SendClientMessage(playerid,RED,string);
        return 
1;
    }
    return 
0;

So it can't be not threadsafe.

Sorry for English.
Reply


Forum Jump:


Users browsing this thread: 9 Guest(s)