User Tools

Site Tools


notification_receive_information_from_sender_thread.htm
Navigation:  Language Reference > 13 - Built-in Functions >====== NOTIFICATION (receive information from sender thread) ====== Previous pageReturn to chapter overviewNext page

NOTIFICATION(notifycode, <;thread>, <;parameter> )

blk2blue.jpg

NOTIFICATION Receives information from a sender thread.
notifycode An UNSIGNED variable that receives a notify code value passed by the sender with a NOTIFY statement.
thread An optional SIGNED variable that receives the number of the sender's thread parameter.
parameter A LONG variable that receives the parameter passed by the sender with a NOTIFY statement.

The NOTIFICATION function is used by a receiving thread. It receives the notification code, thread number, and parameter passed by the sending thread's NOTIFY statement.

NOTIFICATION returns FALSE (0) if the EVENT() function returns an event other than EVENT:Notify. If EVENT:Notify is posted, NOTIFICATION returns TRUE. Because calls to NOTIFY and NOTIFICATION are asynchronous, the sender thread can be closed already when receiver thread accepts the EVENT:Notify event.

NOTIFY and NOTIFICATION are a functional replacement for the SETTARGET(,thread) statement. They can also be used for safe transfer information between threads.

The code between SETTARGET(,thread) and a subsequent SETTARGET is executing in the context of the specified thread but also as a part of the current thread. Hence, two threads can execute the code in the same context. Also, related DLLs can associate their thread dependent data with the Thread ID of the current thread. These aspects make using SETTARGET(,thread) potentially dangerous in the new threading model.

The purpose of NOTIFY and NOTIFICATION is to provide a way to send a notification with parameters from one thread to another. The receiver thread can then execute the request in the correct context.

Return Data Type:     BYTE

Example:

CASE EVENT()

OF EVENT:Accepted

 CASE ACCEPTED()

 OF ?Start

  START (T1)

 OF ?Load

  CALL ('DLL.DLL', 'EntryPoint', 1)

 ELSE

  Q.Feq = ACCEPTED()

  GET (Q, Q.Feq)

  IF ERRORCODE() = 0 AND Q.Op <;> 0

   DM &amp;= Q.ID + 0

   DM.ExecuteMenu (Q.Op)

  END

 END

OF EVENT:Notify

 IF NOTIFICATION (NCode,, NParam) !NOTIFY has sent a Notify Event. Get Code and Parameter

  DM &amp;= NParam + 0                !Assign passed parameter to reference var

  CASE Ncode                      !Test the Notify Code

  OF NOTIFY:Load

   DM.CreateMenu (Q)              !Execute appropriate action

  OF NOTIFY:Unload

   DO DestroyMenu

   UNLOAD ('DLL.DLL')             !Execute appropriate action

  END

 END

END

See Also:

NOTIFY

notification_receive_information_from_sender_thread.htm.txt · Last modified: 2021/04/15 15:57 by 127.0.0.1