HELP: Using ColAndreas in another thread (plugin dev)
#1

Here I cannot get an answer from the developer of CA.

I want to create a PathFinder plugin like this using your plugin instead of MapAndreas. I need using CA functions in other thread. How much safely to use Invoke? Tell me how best. I know nothing, this is my first developing
Tell me something about using CA plugin in a other thread. I have created a plugin long ago for calculating a route for bot system and it doesn't work well because of some troubles related to using of CA in another thread through Invoke. I am creating AI in samp, for example the bot police system!




Let it be for now, but crashes occurs:
https://github.com/Fleynaro/PathFind...9/path.cpp#L91

Crash of my plugin:
PHP код:
backtrace:
#0  0xf621ae9b in ColAndreasNatives::CA_RayCastLine(tagAMX*, int*) () from plugins/ColAndreas.so
No symbol table info available.
#1  0xf5629eec in Invoke::callNative(PAWN::Native const*, ...) () from plugins/PathFinderCA.so
No symbol table info available.
#2  0xf56244b0 in Invoke::CA_RayCastLine(float, float, float, float, float, float, float*, float*, float*) () from plugins/PathFinderCA.so
No symbol table info available.
#3  0xf562297a in Path::CheckWall(mapPoint*, mapPoint*) () from plugins/PathFinderCA.so
No symbol table info available.
#4  0xf5622d58 in Path::Find() () from plugins/PathFinderCA.so
No symbol table info available.
#5  0xf5628221 in Thread::PathCalculator(void*) () from plugins/PathFinderCA.so
No symbol table info available.
#6  0xf562816c in Thread::RunPathCalculator(void*) () from plugins/PathFinderCA.so
No symbol table info available.
#7  0xf7f9d27a in start_thread () from /lib/i386-linux-gnu/libpthread.so.0
No symbol table info available.
#8  0xf7cdaae6 in clone () from /lib/i386-linux-gnu/libc.so.6
No symbol table info available
Reply
#2

continuation of crash...
PHP код:
registers:
eax            0x0    0
ecx            0x2287df80    579329920
edx            0xc5037caf    
-989627217
ebx            0xf62e8000    
-164724736
esp            0xe8ff4040    0xe8ff4040
ebp            0xe8ff4188    0xe8ff4188
esi            0xf660a8d8    
-161437480
edi            0x2287df80    579329920
eip            0xf621ae9b    0xf621ae9b 
<ColAndreasNatives::CA_RayCastLine(tagAMX*, int*)+235>
eflags         0x10282    SF IF RF ]
cs             0x23    35
ss             0x2b    43
ds             0x2b    43
es             0x2b    43
fs             0x0    0
gs             0x63    99
current instructions
:
=> 
0xf621ae9b <_ZN17ColAndreasNatives14CA_RayCastLineEP6tagAMXPi+235>:    mov    %edx,(%eax)
   
0xf621ae9d <_ZN17ColAndreasNatives14CA_RayCastLineEP6tagAMXPi+237>:    mov    0x28(%esp),%eax
   0xf621aea1 
<_ZN17ColAndreasNatives14CA_RayCastLineEP6tagAMXPi+241>:    mov    0x54(%esp),%edx
   0xf621aea5 
<_ZN17ColAndreasNatives14CA_RayCastLineEP6tagAMXPi+245>:    mov    %edx,(%eax)
   
0xf621aea7 <_ZN17ColAndreasNatives14CA_RayCastLineEP6tagAMXPi+247>:    mov    0x2c(%esp),%eax
   0xf621aeab 
<_ZN17ColAndreasNatives14CA_RayCastLineEP6tagAMXPi+251>:    mov    0x58(%esp),%edx
   0xf621aeaf 
<_ZN17ColAndreasNatives14CA_RayCastLineEP6tagAMXPi+255>:    mov    %edx,(%eax)
   
0xf621aeb1 <_ZN17ColAndreasNatives14CA_RayCastLineEP6tagAMXPi+257>:    movzwl 0x22(%esp),%edx
   0xf621aeb6 
<_ZN17ColAndreasNatives14CA_RayCastLineEP6tagAMXPi+262>:    add    $0x60,%esp
   0xf621aeb9 
<_ZN17ColAndreasNatives14CA_RayCastLineEP6tagAMXPi+265>:    mov    %edx,%eax
   0xf621aebb 
<_ZN17ColAndreasNatives14CA_RayCastLineEP6tagAMXPi+267>:    pop    %ebx
   0xf621aebc 
<_ZN17ColAndreasNatives14CA_RayCastLineEP6tagAMXPi+268>:    pop    %esi
   0xf621aebd 
<_ZN17ColAndreasNatives14CA_RayCastLineEP6tagAMXPi+269>:    pop    %edi
   0xf621aebe 
<_ZN17ColAndreasNatives14CA_RayCastLineEP6tagAMXPi+270>:    ret    
   0xf621aebf
:    nop
   0xf621aec0 
<_ZN17ColAndreasNatives16CA_RayCastLineIDEP6tagAMXPi>:    push   %edi
threads backtrace
:
Thread 18 (Thread 0xe8ff4b40 (LWP 23418)):
#0  0xf621ae9b in ColAndreasNatives::CA_RayCastLine(tagAMX*, int*) () from plugins/ColAndreas.so
#1  0xf5629eec in Invoke::callNative(PAWN::Native const*, ...) () from plugins/PathFinderCA.so
#2  0xf56244b0 in Invoke::CA_RayCastLine(float, float, float, float, float, float, float*, float*, float*) () from plugins/PathFinderCA.so
#3  0xf562297a in Path::CheckWall(mapPoint*, mapPoint*) () from plugins/PathFinderCA.so
#4  0xf5622d58 in Path::Find() () from plugins/PathFinderCA.so
#5  0xf5628221 in Thread::PathCalculator(void*) () from plugins/PathFinderCA.so
#6  0xf562816c in Thread::RunPathCalculator(void*) () from plugins/PathFinderCA.so
#7  0xf7f9d27a in start_thread () from /lib/i386-linux-gnu/libpthread.so.0
#8  0xf7cdaae6 in clone () from /lib/i386-linux-gnu/libc.so.6
Thread 17 (Thread 0xe97f5b40 (LWP 23417)):
#0  0xf7fd7c89 in __kernel_vsyscall ()
#1  0xf7ca430a in nanosleep () from /lib/i386-linux-gnu/libc.so.6
#2  0xf7cd3e45 in usleep () from /lib/i386-linux-gnu/libc.so.6
#3  0xf56285d6 in Thread::PathCalculator(void*) () from plugins/PathFinderCA.so
#4  0xf562816c in Thread::RunPathCalculator(void*) () from plugins/PathFinderCA.so
#5  0xf7f9d27a in start_thread () from /lib/i386-linux-gnu/libpthread.so.0
#6  0xf7cdaae6 in clone () from /lib/i386-linux-gnu/libc.so.6
Thread 16 (Thread 0xe9ff6b40 (LWP 23416)):
#0  0xf7fd7c89 in __kernel_vsyscall ()
#1  0xf7fa2b9b in pthread_cond_wait@@GLIBC_2.3.2 () from /lib/i386-linux-gnu/libpthread.so.0
#2  0xf7eb62ae in std::condition_variable::wait(std::unique_lock<std::mutex>&) () from /usr/lib32/libstdc++.so.6
#3  0xf784d4d6 in CThreadedConnection::WorkerFunc() () from plugins/mysql.so
#4  0xf784fd81 in std::thread::_Impl<std::_Bind_simple<std::_Bind<std::_Mem_fn<void (CThreadedConnection::*)()> (CThreadedConnection*)> ()> >::_M_run() () from plugins/mysql.so
#5  0xf7ebca7e in ?? () from /usr/lib32/libstdc++.so.6
#6  0xf7f9d27a in start_thread () from /lib/i386-linux-gnu/libpthread.so.0
#7  0xf7cdaae6 in clone () from /lib/i386-linux-gnu/libc.so.6
Thread 15 (Thread 0xea878b40 (LWP 23414)):
#0  0xf7fd7c89 in __kernel_vsyscall ()
#1  0xf7fa2b9b in pthread_cond_wait@@GLIBC_2.3.2 () from /lib/i386-linux-gnu/libpthread.so.0
#2  0xf7eb62ae in std::condition_variable::wait(std::unique_lock<std::mutex>&) () from /usr/lib32/libstdc++.so.6
#3  0xf784d4d6 in CThreadedConnection::WorkerFunc() () from plugins/mysql.so
#4  0xf784fd81 in std::thread::_Impl<std::_Bind_simple<std::_Bind<std::_Mem_fn<void (CThreadedConnection::*)()> (CThreadedConnection*)> ()> >::_M_run() () from plugins/mysql.so
#5  0xf7ebca7e in ?? () from /usr/lib32/libstdc++.so.6
#6  0xf7f9d27a in start_thread () from /lib/i386-linux-gnu/libpthread.so.0
#7  0xf7cdaae6 in clone () from /lib/i386-linux-gnu/libc.so.6
Thread 14 (Thread 0xeb0fab40 (LWP 23412)):
#0  0xf7fd7c89 in __kernel_vsyscall ()
#1  0xf7fa2b9b in pthread_cond_wait@@GLIBC_2.3.2 () from /lib/i386-linux-gnu/libpthread.so.0
#2  0xf7eb62ae in std::condition_variable::wait(std::unique_lock<std::mutex>&) () from /usr/lib32/libstdc++.so.6
#3  0xf784d4d6 in CThreadedConnection::WorkerFunc() () from plugins/mysql.so
#4  0xf784fd81 in std::thread::_Impl<std::_Bind_simple<std::_Bind<std::_Mem_fn<void (CThreadedConnection::*)()> (CThreadedConnection*)> ()> >::_M_run() () from plugins/mysql.so
#5  0xf7ebca7e in ?? () from /usr/lib32/libstdc++.so.6
#6  0xf7f9d27a in start_thread () from /lib/i386-linux-gnu/libpthread.so.0
#7  0xf7cdaae6 in clone () from /lib/i386-linux-gnu/libc.so.6
Thread 13 (Thread 0xeb97cb40 (LWP 23410)):
#0  0xf7fd7c89 in __kernel_vsyscall ()
#1  0xf7fa2b9b in pthread_cond_wait@@GLIBC_2.3.2 () from /lib/i386-linux-gnu/libpthread.so.0
#2  0xf7eb62ae in std::condition_variable::wait(std::unique_lock<std::mutex>&) () from /usr/lib32/libstdc++.so.6
#3  0xf784d4d6 in CThreadedConnection::WorkerFunc() () from plugins/mysql.so
#4  0xf784fd81 in std::thread::_Impl<std::_Bind_simple<std::_Bind<std::_Mem_fn<void (CThreadedConnection::*)()> (CThreadedConnection*)> ()> >::_M_run() () from plugins/mysql.so
#5  0xf7ebca7e in ?? () from /usr/lib32/libstdc++.so.6
#6  0xf7f9d27a in start_thread () from /lib/i386-linux-gnu/libpthread.so.0
#7  0xf7cdaae6 in clone () from /lib/i386-linux-gnu/libc.so.6
Thread 12 (Thread 0xec17db40 (LWP 23408)):
#0  0xf7fd7c89 in __kernel_vsyscall ()
#1  0xf7fa2b9b in pthread_cond_wait@@GLIBC_2.3.2 () from /lib/i386-linux-gnu/libpthread.so.0
#2  0xf7eb62ae in std::condition_variable::wait(std::unique_lock<std::mutex>&) () from /usr/lib32/libstdc++.so.6
#3  0xf784d4d6 in CThreadedConnection::WorkerFunc() () from plugins/mysql.so
#4  0xf784fd81 in std::thread::_Impl<std::_Bind_simple<std::_Bind<std::_Mem_fn<void (CThreadedConnection::*)()> (CThreadedConnection*)> ()> >::_M_run() () from plugins/mysql.so
#5  0xf7ebca7e in ?? () from /usr/lib32/libstdc++.so.6
#6  0xf7f9d27a in start_thread () from /lib/i386-linux-gnu/libpthread.so.0
#7  0xf7cdaae6 in clone () from /lib/i386-linux-gnu/libc.so.6
Thread 11 (Thread 0xecbffb40 (LWP 23407)):
#0  0xf7fd7c89 in __kernel_vsyscall ()
#1  0xf7fa2b9b in pthread_cond_wait@@GLIBC_2.3.2 () from /lib/i386-linux-gnu/libpthread.so.0
#2  0xf7eb62ae in std::condition_variable::wait(std::unique_lock<std::mutex>&) () from /usr/lib32/libstdc++.so.6
#3  0xf784d4d6 in CThreadedConnection::WorkerFunc() () from plugins/mysql.so
#4  0xf784fd81 in std::thread::_Impl<std::_Bind_simple<std::_Bind<std::_Mem_fn<void (CThreadedConnection::*)()> (CThreadedConnection*)> ()> >::_M_run() () from plugins/mysql.so
#5  0xf7ebca7e in ?? () from /usr/lib32/libstdc++.so.6
#6  0xf7f9d27a in start_thread () from /lib/i386-linux-gnu/libpthread.so.0
#7  0xf7cdaae6 in clone () from /lib/i386-linux-gnu/libc.so.6
Thread 10 (Thread 0xed503b40 (LWP 23406)):
#0  0xf7fd7c89 in __kernel_vsyscall ()
#1  0xf7fa2b9b in pthread_cond_wait@@GLIBC_2.3.2 () from /lib/i386-linux-gnu/libpthread.so.0
#2  0xf7eb62ae in std::condition_variable::wait(std::unique_lock<std::mutex>&) () from /usr/lib32/libstdc++.so.6
#3  0xf784d4d6 in CThreadedConnection::WorkerFunc() () from plugins/mysql.so
#4  0xf784fd81 in std::thread::_Impl<std::_Bind_simple<std::_Bind<std::_Mem_fn<void (CThreadedConnection::*)()> (CThreadedConnection*)> ()> >::_M_run() () from plugins/mysql.so
#5  0xf7ebca7e in ?? () from /usr/lib32/libstdc++.so.6
#6  0xf7f9d27a in start_thread () from /lib/i386-linux-gnu/libpthread.so.0
#7  0xf7cdaae6 in clone () from /lib/i386-linux-gnu/libc.so.6
Thread 9 (Thread 0xedd04b40 (LWP 23405)):
#0  0xf7fd7c89 in __kernel_vsyscall ()
#1  0xf7fa2b9b in pthread_cond_wait@@GLIBC_2.3.2 () from /lib/i386-linux-gnu/libpthread.so.0
#2  0xf7eb62ae in std::condition_variable::wait(std::unique_lock<std::mutex>&) () from /usr/lib32/libstdc++.so.6
#3  0xf784d4d6 in CThreadedConnection::WorkerFunc() () from plugins/mysql.so
#4  0xf784fd81 in std::thread::_Impl<std::_Bind_simple<std::_Bind<std::_Mem_fn<void (CThreadedConnection::*)()> (CThreadedConnection*)> ()> >::_M_run() () from plugins/mysql.so
#5  0xf7ebca7e in ?? () from /usr/lib32/libstdc++.so.6
#6  0xf7f9d27a in start_thread () from /lib/i386-linux-gnu/libpthread.so.0
#7  0xf7cdaae6 in clone () from /lib/i386-linux-gnu/libc.so.6
Thread 8 (Thread 0xee505b40 (LWP 23404)):
#0  0xf7fd7c89 in __kernel_vsyscall ()
#1  0xf7fa2b9b in pthread_cond_wait@@GLIBC_2.3.2 () from /lib/i386-linux-gnu/libpthread.so.0
#2  0xf7eb62ae in std::condition_variable::wait(std::unique_lock<std::mutex>&) () from /usr/lib32/libstdc++.so.6
#3  0xf784d4d6 in CThreadedConnection::WorkerFunc() () from plugins/mysql.so
#4  0xf784fd81 in std::thread::_Impl<std::_Bind_simple<std::_Bind<std::_Mem_fn<void (CThreadedConnection::*)()> (CThreadedConnection*)> ()> >::_M_run() () from plugins/mysql.so
#5  0xf7ebca7e in ?? () from /usr/lib32/libstdc++.so.6
#6  0xf7f9d27a in start_thread () from /lib/i386-linux-gnu/libpthread.so.0
#7  0xf7cdaae6 in clone () from /lib/i386-linux-gnu/libc.so.6
Thread 7 (Thread 0xeed06b40 (LWP 23403)):
#0  0xf7fd7c89 in __kernel_vsyscall ()
#1  0xf7fa2b9b in pthread_cond_wait@@GLIBC_2.3.2 () from /lib/i386-linux-gnu/libpthread.so.0
#2  0xf7eb62ae in std::condition_variable::wait(std::unique_lock<std::mutex>&) () from /usr/lib32/libstdc++.so.6
#3  0xf784d4d6 in CThreadedConnection::WorkerFunc() () from plugins/mysql.so
#4  0xf784fd81 in std::thread::_Impl<std::_Bind_simple<std::_Bind<std::_Mem_fn<void (CThreadedConnection::*)()> (CThreadedConnection*)> ()> >::_M_run() () from plugins/mysql.so
#5  0xf7ebca7e in ?? () from /usr/lib32/libstdc++.so.6
#6  0xf7f9d27a in start_thread () from /lib/i386-linux-gnu/libpthread.so.0
#7  0xf7cdaae6 in clone () from /lib/i386-linux-gnu/libc.so.6
Thread 6 (Thread 0xf3bd0b40 (LWP 23402)):
#0  0xf7fd7c89 in __kernel_vsyscall ()
#1  0xf7fa2b9b in pthread_cond_wait@@GLIBC_2.3.2 () from /lib/i386-linux-gnu/libpthread.so.0
#2  0xf7eb62ae in std::condition_variable::wait(std::unique_lock<std::mutex>&) () from /usr/lib32/libstdc++.so.6
#3  0xf784d4d6 in CThreadedConnection::WorkerFunc() () from plugins/mysql.so
#4  0xf784fd81 in std::thread::_Impl<std::_Bind_simple<std::_Bind<std::_Mem_fn<void (CThreadedConnection::*)()> (CThreadedConnection*)> ()> >::_M_run() () from plugins/mysql.so
#5  0xf7ebca7e in ?? () from /usr/lib32/libstdc++.so.6
#6  0xf7f9d27a in start_thread () from /lib/i386-linux-gnu/libpthread.so.0
#7  0xf7cdaae6 in clone () from /lib/i386-linux-gnu/libc.so.6
Thread 4 (Thread 0xf6ff6b40 (LWP 23400)):
#0  0xf7fd7c89 in __kernel_vsyscall ()
#1  0xf7ca430a in nanosleep () from /lib/i386-linux-gnu/libc.so.6
#2  0xf7cd3e45 in usleep () from /lib/i386-linux-gnu/libc.so.6
#3  0x08076410 in ?? ()
#4  0xf7f9d27a in start_thread () from /lib/i386-linux-gnu/libpthread.so.0
#5  0xf7cdaae6 in clone () from /lib/i386-linux-gnu/libc.so.6
Thread 2 (Thread 0xf77f7b40 (LWP 23398)):
#0  0xf7fd7c89 in __kernel_vsyscall ()
#1  0xf7fa2b9b in pthread_cond_wait@@GLIBC_2.3.2 () from /lib/i386-linux-gnu/libpthread.so.0
#2  0xf7eb62ae in std::condition_variable::wait(std::unique_lock<std::mutex>&) () from /usr/lib32/libstdc++.so.6
#3  0xf7801289 in CLogManager::Process() () from /home/fleynaro/samp/plugins/../log-core.so
#4  0xf7806851 in std::thread::_Impl<std::_Bind_simple<std::_Bind<std::_Mem_fn<void (CLogManager::*)()> (CLogManager*)> ()> >::_M_run() () from /home/fleynaro/samp/plugins/../log-core.so
#5  0xf7ebca7e in ?? () from /usr/lib32/libstdc++.so.6
#6  0xf7f9d27a in start_thread () from /lib/i386-linux-gnu/libpthread.so.0
#7  0xf7cdaae6 in clone () from /lib/i386-linux-gnu/libc.so.6
Thread 1 (Thread 0xf7bf2140 (LWP 23394)):
#0  0xf7fd7c89 in __kernel_vsyscall ()
#1  0xf7ca430a in nanosleep () from /lib/i386-linux-gnu/libc.so.6
#2  0xf7cd3e45 in usleep () from /lib/i386-linux-gnu/libc.so.6
#3  0x080aa172 in ?? ()
#4  0xf7c0b286 in __libc_start_main () from /lib/i386-linux-gnu/libc.so.6
#5  0x0804b4e1 in ?? () 
Reply
#3

poor man
Reply
#4

Quote:
Originally Posted by ******
Посмотреть сообщение
Threads are hard. Experts get them wrong. If this is your first plugin, I'd suggest avoiding them for now - make a single threaded version first, then maybe try extend it later once you have learnt more.
The threads are so not hard for me, at least it`s I thinks so. Just It`s very important to get any answer from CA plugin`s developers, that cannot help me about this for some reason...

As for using in the single thread, it will be very slowly because there`re a lot of calculations and the slowest CA_ functs will be called
Reply
#5

Honestly cant really help. I don't know much about threads. It took a long time to get ColAndreas to work but finally one night we started seeing the first collisions working it was a lot of effort for just one function really. You will have a similar experience it takes a lot of work to get results. I suggest not focusing on threads but making sure it works well.
Reply
#6

Quote:
Originally Posted by Pottus
Посмотреть сообщение
Honestly cant really help. I don't know much about threads. It took a long time to get ColAndreas to work but finally one night we started seeing the first collisions working it was a lot of effort for just one function really. You will have a similar experience it takes a lot of work to get results. I suggest not focusing on threads but making sure it works well.
I decided to try to solve the problem myself, and I found one intersting thing: crashes occurs due FCNPC_Create calling. I used mutex, lock CA before calling of FCNPC_Create and unlock after its calling and crashes disappeared! It`s very strange, why FCNPC plugin has anything to do to PathFinder plugin and CA. Now, It seems to work well. For now.
Reply
#7

You are multi-threading stuff in a well let's say single threaded enviroment.
Unexpected behaviour and race conditions are guaranteed as long as you do synergise them together properly.

You shouldn't touch any scripting stuff from your threads, ALWAYS make sure you're on the main thread before doing anything.

Your fix isn't really a fix either, you're just patching holes on a sinking ship, you're better off integrating some kind of api in ColAndreas to access that data, even then you can't be sure that the script thread is accessing/writing some data from the ColAndreas plug-in itself.

Do not spam threads and locks till everything is working, it'll sooner or later end in a chaos of random exceptions.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)