Login
Username:

Password:

Remember me



Lost Password?

Register now!

Sections

Who's Online
14 user(s) are online (8 user(s) are browsing Forums)

Members: 0
Guests: 14

more...

Support us!

Headlines

 
  Register To Post  

« 1 ... 3 4 5 (6) 7 8 9 »
Re: New verson of CLiB2 from Andrea (afxgroup)
Quite a regular
Quite a regular


See User information
@afxgroup

Hi, I noticed the cause for the hanging of threads.

I have not figured out exactly why or the elegant solution, but, in the situation where I have a simple program (known, now, as the "main thread") that then creates a thread (known, now, as the "child thread"); where, child thread loops constantly until some request from the main thread - in my case - pthraed_cancel(childThread);

In this case, it seems like (pthread_join.c):
Wait(SIGF_PARENT);

Will never receive the signal.

At (StartFunc / pthread_create.c)
Printf("[%s] Finishing stuff\n"inf->name);

the issue seems to be that
if (inf->status == THREAD_STATE_RUNNING) {

is NOT true. Then, no "Signal(inf->parent, SIGF_PARENT);" is performed.

In that case, the parent thread is left WAITING.

To test it, I hacked in
Forbid();
    
Signal(inf->parentSIGF_PARENT);

to be executed - regardless. Now, child thread shuts down, which it does anyway, but also the main thread shuts down because it receives the signal.

===

Alternatively to modifying anything in the clib2/pthread branch, you can issue something like a Delay(150) between "pthread_cancel" and "pthread_join" in your own user program without adding any hacks to the current clib2/pthreads branch - and you may be able to see that in that case the main thread is also not left WAITING and that it successfully closes.

===

Here is the test code:

Can toggle the commenting of IDOS->Delay. Forget about the "sound thread" that was just some extra testing. Ofc, requires SDL2.

#include <SDL2/SDL.h>
#include <pthread.h>
#include <time.h>

#include <proto/dos.h> /* just for Delay */

#define MSG(msg) { fprintf(stderr,"%s\n",msg); fflush(stderr); }
#define BAIL(msg,ret) { MSG(msg) ; RET=ret; goto ENDER; }

int RET=0;
SDL_Window *window;
SDL_Renderer *render;
SDL_Event ev;
int quit=0;

int vel_x=3,vel_y=-2;

/* thread stuff*/
pthread_t thread_s;
pthread_t thread_e;
// void* thread_sound(void*);
voidthread_engine(void*);
int retval_sound,retval_engine;

Uint8 r=0xFF,g=0x00,b=0x00;

/* gfx */
SDL_Rect block = { 400,300,10,10};

int main(int argcchar *argv[])
{
    (
void)argc;(void)argv;
    if(
SDL_Init(SDL_INIT_VIDEO|SDL_INIT_AUDIO))
    {
        
BAIL(SDL_GetError(),10);
    }
    if(
SDL_CreateWindowAndRenderer(800,600,0/*no flags*/,&window,&render))
    {
        
BAIL(SDL_GetError(),20);
    }
    
SDL_SetWindowTitle(window,"thread_test");
    
// /* now let's create a thread for some sound */
    // if(pthread_create(&thread_s,NULL,&thread_sound,NULL))
    // {
    //     BAIL("Unable to create a thread for sound",30);
    // }
    /* and, a thread for some sort of engine */
    
if(pthread_create(&thread_e,NULL,&thread_engine,NULL))
    {
        
BAIL("Unable to create a thread for engine",31);
    }
    
    while(!
quit)
    {
        while(
SDL_PollEvent(&ev))
        {
            if(
ev.type == SDL_QUIT)
            {
                
quit=1;
            }
        }
        
        
SDL_SetRenderDrawColor(render,0x00,0x00,0x00,0x00);
        
SDL_RenderClear(render); /* draw an empty black screen! */
        
        
SDL_SetRenderDrawColor(render,r,g,b,0x00);
        
SDL_RenderFillRect(render,&block);
        
SDL_RenderPresent(render);
        
        
SDL_Delay(33);
    }
    
    
// /* we get here if we quit */
    // if(pthread_cancel(thread_s))
    // {
    //     BAIL("Failed to cancel sound thread!",40);
    // }
    
    /* we get here if we quit */
    
if(pthread_cancel(thread_e))
    {
        
BAIL("Failed to cancel engine thread!",41);
    }
    else
    {
      
printf("We canceled it!\n");
    }
    
    
// /* wait for the thread to finish */
    // if(pthread_join(thread_s,NULL))
    // {
    //     BAIL("Could not join sound thread!",50);
    // }
    /*IDOS->Delay(150);*/
    
    
printf("Calling pthread_join!\n");
    if(
pthread_join(thread_e,NULL))
    {
        
BAIL("Could not join engine thread!",51);
    }
    else
    {
      
printf("We joined it!\n");
    }
ENDER:
    if(
renderSDL_DestroyRenderer(render);
    if(
windowSDL_DestroyWindow(window);
    
SDL_Quit();
    return 
RET;
}

// void* thread_sound(void* args)
// {
//     (void)args;
//     struct timespec ts;
//     for(;;)
//     {
//         pthread_testcancel();
//         if(clock_gettime(CLOCK_REALTIME,&ts))
//         {
//             MSG("Unsuccessful call to clock_gettime()");
//         }
//         printf("Time: %llu\n",ts.tv_sec);
//     }
// }

voidthread_engine(voidargs)
{
    (
void)args;
    for(;;)
    {
        
pthread_testcancel();
        if((
block.800)||(block.x<0))
            
vel_x=-(vel_x);
        if((
block.600)||(block.y<0))
            
vel_y=-(vel_y);
        
        
block.x+=vel_x;
        
block.y+=vel_y;
        
        if(
block.x>400)
        {
            
r=0x00;
            
g=0x00;
            
b=0xFF;
        }
        else
        {
            
r=0xFF;
            
g=0x00;
            
b=0x00;
        }
    }
}

If liberty means anything at all, it means the right to tell people what they do not want to hear.
George Orwell.
Go to top
Re: New verson of CLiB2 from Andrea (afxgroup)
Quite a regular
Quite a regular


See User information
Perhaps:
git diff
diff 
--git a/library/pthread/pthread_create.c b/library/pthread/pthread_create.c
index 2005efb
..d4c2a00 100644
--- a/library/pthread/pthread_create.c
+++ b/library/pthread/pthread_create.c
@@ -90,+90,@@ StarterFunc() {
         
StackSwap(&stack);
 
     
Printf("[%s] Finishing stuff\n"inf->name);
-    if (
inf->status == THREAD_STATE_RUNNING) {
+    if (
inf->status == THREAD_STATE_RUNNING || inf->status == THREAD_STATE_JOINING) {^M
         
if (!inf->detached) {
             
Printf("[%s] Signal parent %p\n"inf->nameinf->parent);
             
// tell the parent thread that we are done
@@ -108,+108,@@ StarterFunc() {
         }
     }
     else
-        
Printf("[%s] Thread was not running\n"inf->name);
+        
Printf("[%s] Thread was not running or joining\n"inf->name);^M
     Printf
("[%s] Exit StarterFunc\n"inf->name);
 
     return 
RETURN_OK;
@@ -
202,+202,@@ pthread_create(pthread_t *thread, const pthread_attr_t *attrvoid *(*start)(voi
 
     Printf
("\n[%s] pthread_create done\n"inf->name);
     return 
OK;
-}
\ No newline at end of file
+}^M


Since we can get in the situation where the code in pthread_join is called (setting the status to JOINING) before needing to give the final signal to the parent thread (which assumes that the state will only be in the RUNNING state).

But, I could be way off! But, this works for my personal example. I should run the full tests since it may have broken other things!

===
PS:
DOS line endings are expected in this repository?

If liberty means anything at all, it means the right to tell people what they do not want to hear.
George Orwell.
Go to top
Re: New verson of CLiB2 from Andrea (afxgroup)
Amigans Defender
Amigans Defender


See User information
Thank you! Tomorrow I'll travel to Germany for holidays so I can't test this changes at moment. I'll be back in a week and I'll try your changes. In the meanwhile, if you find other issues and you can test everything deeply would be really apreciated! :)

i'm really tired...
Go to top
Re: New verson of CLiB2 from Andrea (afxgroup)
Amigans Defender
Amigans Defender


See User information
BTW, I've seen your pull requests but you have reverted your changes. I'll commit them one by one

i'm really tired...
Go to top
Re: New verson of CLiB2 from Andrea (afxgroup)
Quite a regular
Quite a regular


See User information
Right,

Git ans github always baffles me. I just prefer SVN.

I can correct the pull requests if you want, or, let you handle it. Let me know.

If liberty means anything at all, it means the right to tell people what they do not want to hear.
George Orwell.
Go to top
Re: New verson of CLiB2 from Andrea (afxgroup)
Amigans Defender
Amigans Defender


See User information
i'll handle them. However no need to change INSTALL_PREFIX and SDK_INCLUDE in makefile. Just pass them to GNUMakefile.os4 and they will be overridden

i'm really tired...
Go to top
Re: New verson of CLiB2 from Andrea (afxgroup)
Quite a regular
Quite a regular


See User information
Yeah I know, makefile ?= handles that.

But really, these are my private changes that should not be visible anyway.

Thanks.

If liberty means anything at all, it means the right to tell people what they do not want to hear.
George Orwell.
Go to top
Re: New verson of CLiB2 from Andrea (afxgroup)
Amigans Defender
Amigans Defender


See User information
However no luck. If you try try_to_time or simple examples in threads test_programs folder you will see the error.
It seems that a function is called when thread is no more running and so you get an ISI error

i'm really tired...
Go to top
Re: New verson of CLiB2 from Andrea (afxgroup)
Quite a regular
Quite a regular


See User information
Thanks, let me use those tests and see what I can do.

If liberty means anything at all, it means the right to tell people what they do not want to hear.
George Orwell.
Go to top
Re: New verson of CLiB2 from Andrea (afxgroup)
Amigans Defender
Amigans Defender


See User information
Fixed and merged :)
Everything is in beta7 branch, working and tested (plus some other improvements..)
So we have a non closed pthread implementation that "seems" to work correctly. Of course more tests needs to be done

EDIT:
beta7 merged into master

i'm really tired...
Go to top
Re: New verson of CLiB2 from Andrea (afxgroup)
Amigans Defender
Amigans Defender


See User information

i'm really tired...
Go to top
Re: New verson of CLiB2 from Andrea (afxgroup)
Quite a regular
Quite a regular


See User information
@afxgroup

Excellent news!

If liberty means anything at all, it means the right to tell people what they do not want to hear.
George Orwell.
Go to top
Re: New verson of CLiB2 from Andrea (afxgroup)
Home away from home
Home away from home


See User information
@rjd324

Mmm pthread fixed on clib2... just the current issue we are discussing.. 😀

Sam440ep Flex 800Mhz 160GB HD + AmigaOS 4.1
Go to top
Re: New verson of CLiB2 from Andrea (afxgroup)
Amigans Defender
Amigans Defender


See User information
but this doesn't help in the call_once problem

i'm really tired...
Go to top
Re: New verson of CLiB2 from Andrea (afxgroup)
Amigans Defender
Amigans Defender


See User information
In beta8 I've fixed a memory leak when using posix_memalign and now all memory seems to be freed once the program exit

i'm really tired...
Go to top
Re: New verson of CLiB2 from Andrea (afxgroup)
Home away from home
Home away from home


See User information
@Andrea
Tried to build some other stuff which compiles ok via newlib, but fail with clib2. Error which i have is:

/amiga/glsl-optimizer-amigaos4/glsl-optimizer/src/glsl/main.cpp:314:34errorinvalid conversion from â€˜char**’ to â€˜const char**’ [-fpermissive]
  
314 |    while ((getopt_long(argcargv""compiler_opts, &idx)) != -1) {
      |                                  ^~~~
      |                                  |
      |                                  
char**


While for newlib compiles error-free.

I had to cast it with (const char**) , but point is that it should compiles without error as on newlib imho.

Join us to improve dopus5!
AmigaOS4 on youtube
Go to top
Re: New verson of CLiB2 from Andrea (afxgroup)
Home away from home
Home away from home


See User information
@kas1e

Did you try to revert your "const char**" change for clib2?

Go to top
Re: New verson of CLiB2 from Andrea (afxgroup)
Home away from home
Home away from home


See User information
@Raziel
I mean this error happens with original code (without const char **cast being added). And to make it compiles over clib2, i had to add this const, while should't.

Join us to improve dopus5!
AmigaOS4 on youtube
Go to top
Re: New verson of CLiB2 from Andrea (afxgroup)
Amigans Defender
Amigans Defender


See User information
In the old clib2 was defined in a different way.
I have changed the definition to match the correct function declaration but I have to test the changes. You will find it in next commit on beta8

i'm really tired...
Go to top
Re: New verson of CLiB2 from Andrea (afxgroup)
Home away from home
Home away from home


See User information
@Andrea

Have few questions about clib2:


1.
Are clib2 didn't have working ieeefp stuff ? I just found that once i enable HAVE_IEEEFP_H as for newlib, it says that ieeefp.h include not found (i checked in clib2, there is none, whyle newlib have one)

2.
Also i tried to build Salas00's OpenAll for latest clib2, and have that:

./OpenAL32/Include/alMain.h:985:48errorformat â€˜%lu’ expects argument of type â€˜long unsigned int’but argument 5 has type â€˜off_t’ {aka â€˜long long int’} [-Werror=format=]
  
985 #define AL_PRINT(T, MSG, ...) fprintf(LogFile, "AL lib: %s %s: "MSG, T, __FUNCTION__ , ## __VA_ARGS__)


Not sure through if it issue with clib2, or with more warnings in gcc 11.3.0


3. Tried to rebuild some stuff which builds ok on newlib, and have that on linking:

SoundFileWriterWav.cpp:(.text+0xf4): undefined reference to `_ZNSo5seekpESt4fposI10_mbstate_tE'
SoundFileWriterWav.cpp:(.text+0x148): undefined reference to `_ZNSo5seekpESt4fposI10_mbstate_tE'
../../build/lib/test-system-s.a(Err.cpp.obj):(.rodata+0x1c): undefined reference to `_ZNSt15basic_streambufIcSt11char_traitsIcEE7seekposESt4fposI10_mbstate_tESt13_Ios_Openmode'

Have any idea wtf happens here ?

That happens as i see for "m_file.seekp(4)" calls. And m_file opened like this:

m_file.open(filename.c_str(), std::ios::binary);


So something seems wrong in there and we have 2 errors in my example:

First one with seekp().
Second one with static std::ostream stream(&buffer);

But both of them mention "mbstate", so i assume issue is same for both problems.

Rechecked on newlib - works and builds ok


Edited by kas1e on 2022/9/19 7:52:01
Edited by kas1e on 2022/9/19 8:03:33
Edited by kas1e on 2022/9/19 8:06:02
Edited by kas1e on 2022/9/19 8:06:53
Edited by kas1e on 2022/9/19 8:21:42
Edited by kas1e on 2022/9/19 8:24:33
Join us to improve dopus5!
AmigaOS4 on youtube
Go to top

  Register To Post
« 1 ... 3 4 5 (6) 7 8 9 »

 




Currently Active Users Viewing This Thread: 1 ( 0 members and 1 Anonymous Users )




Powered by XOOPS 2.0 © 2001-2024 The XOOPS Project