threadcreate()

Forum for discussion about the documentation project.
Post Reply
speedfixer
Posts: 606
Joined: Nov 28, 2012 1:27
Location: CA, USA moving to WA, USA
Contact:

threadcreate()

Post by speedfixer »

No problem with the existing text.


Perhaps add a small note to resolve a question asked of me:

The arguments passed to threadcreate() are not expected to match the arguments to be passed to the sub() used in the new thread.
Your sub() - as a thread - must handle or ignore that pointer.

david
Tourist Trap
Posts: 2958
Joined: Jun 02, 2015 16:24

Re: threadcreate()

Post by Tourist Trap »

Hi,

From my side, as far as I can read the doc, it seems quite clear to me. Even more if I take a look at the provided examples. They don't take a lot of care of the additionnal arguments coming after the @proc argument. In those examples those are either a 0 pointer, or just nothing...

Code: Select all

Sub mythread(param As Any Ptr)
...
ThreadCreate(@mythread, 0)

Code: Select all

Sub consumer( ByVal param As Any Ptr )
...
ThreadCreate(@consumer)
Only the first example maybe can be more ambiguous.

Code: Select all

Sub thread( ByVal userdata As Any Ptr )
...
ThreadCreate(@thread, CPtr(Any Ptr, i))
fxm
Moderator
Posts: 12081
Joined: Apr 22, 2009 12:46
Location: Paris suburbs, FRANCE

Re: threadcreate()

Post by fxm »

In the second and third example, 'userdata' is not used in the sub 'myThread'.
For this, there is two solutions:
- Second example: pass an 'any ptr' containing any value (the value '0' is simple to use because it is directly compatible with any pointer).
- Third example: pass nothing.

In the first example, 'userdata' is used in the sub 'myThread' and allows to number the thread in its displayed message (from '0' to 'MAX_THREADS-1').
Because there are values different from '0', this integer 'i' must be casted into an 'any ptr' when passed to 'threadcreate', then back-casted into an 'integer' in the sub 'myThread' before use.
speedfixer
Posts: 606
Joined: Nov 28, 2012 1:27
Location: CA, USA moving to WA, USA
Contact:

Re: threadcreate()

Post by speedfixer »

I don't have any problem with the current text or the examples.

I DO still remember how much effort it takes to master learning about using any languages' particular syntax using threads and pointers.
For any of the tougher programming concepts, I always review how I use the language and any changes that have come along since I started. Clarifying that pointers to a sub or pointers to a function are really different, specific types is one of those changes.

We pass a pointer that should be of type 'sub pointer' to thread creation. For non-trivial threads, pointers are the key to their operation.

Researching related entries to 'type: sub' in the wiki can suggest that any reference to a sub type pointer might need the arguments to the sub pointer to be included in any declaration of that (sub pointer) type. Certainly not true for creating a thread.

Yes, one can *infer* from the examples that any arguments to a sub in a sub thread need not be referenced. NOT making that tiny statement just feels incomplete to me. (My job before I retired was 80% correcting errors made by people who learned their job by inference. Excellent training or even available documents would have fixed that. 20% of my effort went into fixing that systemic problem. Me and my staff existed only because someone did NOT do an excellent job. A totally non-productive scenario. NO ONE was happy when me or a tech of mine showed up at a job site.)

Our docs are excellent - and improving. They are handled by people that care very much about correctness and helping others use FB. They can only do their work through suggestions from others.

If no one agrees, that's fine. I just like to make things as easy as possible for beginners, without requiring a long, tedious search through the complete wiki to reasonably understand a topic.

david
fxm
Moderator
Posts: 12081
Joined: Apr 22, 2009 12:46
Location: Paris suburbs, FRANCE

Re: threadcreate()

Post by fxm »

Added note (see ThreadCreate documentation page).
speedfixer
Posts: 606
Joined: Nov 28, 2012 1:27
Location: CA, USA moving to WA, USA
Contact:

Re: threadcreate()

Post by speedfixer »

Thank you
Post Reply